Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find number of occurrences of a substring in a string java

public static int count(String str, String target) {
    return (str.length() - str.replace(target, "").length()) / target.length();
}
Comment

count occurrences of character in string java 8

String someString = "elephant";
long count = someString.chars().filter(ch -> ch == 'e').count();
assertEquals(2, count);
 
long count2 = someString.codePoints().filter(ch -> ch == 'e').count();
assertEquals(2, count2);
Comment

count the number of occurrences of a character in a string java

String line = "apples.oranges.bananas";
int count = line.length() - line.replace(".", "").length();
System.out.println(count);//displays 2
Comment

PREVIOUS NEXT
Code Example
Java :: $JAVA_HOME ENV 
Java :: primefaces download file 
Java :: Java ArrayList Class of Collections 
Java :: java math ceil 
Java :: hashmap in java 
Java :: how to remove a sting character in java 
Java :: how to sort arraylist 
Java :: convert calendar to date java 
Java :: java arraylist with double 
Java :: android studio remove button onclick 
Java :: html alert box android 
Java :: convert class to java 
Java :: how to read text file as variable in java 
Java :: java set 
Java :: boolean in java 
Java :: java check if int 
Java :: get intersection of two lists java 
Java :: spring security after login redirect 
Java :: Java How to use Map? 
Java :: check if duplicate element in java 
Java :: thread implements runnable 
Java :: Missing artifact com.sun.jersey:jersey-servlet:jar:1.20-SNAPSHOT 
Java :: javafx edit list 
Java :: java grösser gleich 
Java :: integer parse int exceptions 
Java :: 2d array length in java 
Java :: read excel file in java and store into arraylist 
Java :: selenium drag slider 
Java :: java new string 
Java :: JFrame change border 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =