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 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 :: split number java 
Java :: How to find the next greater permutation of a list of numbers, in Java? 
Java :: how to cast from int to string java 
Java :: how to assert that an exception is thrown java 
Java :: double.parsedouble in java 
Java :: how to make java list 
Java :: JAVA Display Sum of n Natural Numbers 
Java :: how to convert a number into a decimal number in java 
Java :: android remove focus from an element 
Java :: measure running time of a statement java 
Java :: create java gui intellij 
Java :: how to add element to end of array java 
Java :: Simple gui in java 
Java :: guessing game in java 
Java :: write an infinite loop java 
Java :: public static void main vs static public void main 
Java :: iterate through an arraylist java 
Java :: java string to double comma 
Java :: jdbc interface 
Java :: change color of drawable android studio 
Java :: java replace character 
Java :: java string length validation regex 
Java :: bukkit java get player count 
Java :: make edittext not editable android 
Java :: How to draw Bezier Curve in Android 
Java :: java basic syntax 
Java :: how to use arrays java 
Java :: center textview programmatically android 
Java :: apache commons collections android dependency 
Java :: set view size android 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =