Answers for "counting the number of occurrences of a integer in a string java"

3

count the number of words in a string java

public static void main(String[] args)
    { 
        //return the number of words in a string 
        
       String example = "This is a good exercise"; 
       
       int length = example.split(" ").length;
       
       System.out.println("The string is " + length + " words long.");
        
        
    }
Posted by: Guest on June-04-2020
0

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();
}
Posted by: Guest on October-29-2020

Code answers related to "counting the number of occurrences of a integer in a string java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language