Count Duplicate Words
Count Duplicate Words
HashMap;
import java.util.Map;
if (wordCount.containsKey(lowerCaseWord)) {
// If the word is already in the map, increment its count
wordCount.put(lowerCaseWord, wordCount.get(lowerCaseWord) + 1);
} else {
// If the word is not in the map, add it with a count of 1
wordCount.put(lowerCaseWord, 1);
}
}
int count;
///////////////////////////////////////////////////
} else {
map.put(t, 1);
}
}
Set<String> keys = map.keySet();
for (String key : keys) {
System.out.println(key);
System.out.println(map.get(key));
}
}
}
//////////////////////////////////////////////////////////////////
////////////////////////////////////
Java program to find all duplicate characters in a string
Output
The string is:beautiful beach
Duplicate Characters in above string are: b e a u
///////////////////////////////////////////////////////////////////////////////