Answers for "java count certain characters in a string"

2

number of occurence string in java

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');
    }


}
Posted by: Guest on January-14-2021
0

java get how many letters in a string

String str = "a string";
int length = str.length( ); // length == 8
Posted by: Guest on January-27-2021

Code answers related to "java count certain characters in a string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language