Answers for "java check how many specific letter in word"

1

how to test how many of one character is in a string java

int count = string.length() - string.replaceAll("g","").length()
Posted by: Guest on June-02-2020
0

check how many of a word is in a string

function countOccurences(str,word)  
{ 
    // split the string by spaces in a 
    String a[] = str.split(","); 
  
    // search for pattern in a 
    int count = 0; 
    for (int i = 0; i < a.length; i++)  
    { 
    // if match found increase count 
    if (word.equals(a[i])) 
        count++; 
    } 
  
    return count; 
}
Posted by: Guest on November-16-2020

Code answers related to "java check how many specific letter in word"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language