how to count the occurrences of the elements in the string code example
Example 1: how to count the occurrence of a word in string python
string = "Python is awesome, isn't it?"
substring = "is"
count = string.count(substring)
print("The count is:", count)
Example 2: number of occurence in string
public class StringNumberOfOccurenceLetter {
private static int countOccurences(String word, char character){
int count = 0;
for (int i = 0; i < word.length() ; i++) {
if (word.charAt(i)==character){
count++;
}
}
return count;
}
public static void main(String[] args) {
int count = countOccurences("dddssad", 'a');
}
}