Calculating frequency of each word in a sentence in java
Use a map with word as a key and count as value, somthing like this Map<String, Integer> map = new HashMap<>(); for (String w : words) { Integer n = map.get(w); n = (n == null) ? 1 : ++n; map.put(w, n); } if you are not allowed to use java.util then you can sort … Read more