I need to find repeated words on a string, and then count how many times they were repeated. So basically, if the input string is this:
String s = \"House, House
I hope this will help you
public void countInPara(String str) {
Map strMap = new HashMap();
List paraWords = Arrays.asList(str.split(" "));
Set strSet = new LinkedHashSet<>(paraWords);
int count;
for(String word : strSet) {
count = Collections.frequency(paraWords, word);
strMap.put(count, strMap.get(count)==null ? word : strMap.get(count).concat(","+word));
}
for(Map.Entry entry : strMap.entrySet())
System.out.println(entry.getKey() +" :: "+ entry.getValue());
}