Answers for "count frequency of characters in string java"

0

get frequency of letters java

HashMap<Character, Integer> map = new HashMap<Character, Integer>();
String s = "aasjjikkk";
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    Integer val = map.get(c);
    if (val != null) {
        map.put(c, new Integer(val + 1));
    }
    else {
       map.put(c, 1);
   }
}
Posted by: Guest on September-30-2020

Code answers related to "count frequency of characters in string java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language