In this Java program, you’ll learn how to Find the Frequency of Characters in a String using the Java programming language.
How Find the Frequency of Characters in a String using JAVA?
Example 1:
RUN CODE SNIPPETpublic class Main {
public static void main(String[] args) {
String str = "This website is awesome.";
char ch = 'e';
int frequency = 0;
for(int i = 0; i < str.length(); i++) {
if(ch == str.charAt(i)) {
++frequency;
}
}
System.out.println("Frequency of " + ch + " = " + frequency);
}
}OUTPUT
Frequency of e = 4