Is there any way to write the following code using Streams?
public Map<String, Integer> process() {
List<String> words = Arrays.asList(message.toLowerCase().split("[?.\\s]+"));
Map<String, Integer> countMap = new HashMap<>();
for (String word : words) {
if (word.length() > 2) {
Integer count = countMap.getOrDefault(word, 0);
countMap.put(word, count + 1);
}
}
return countMap;
}
Pattern.compile("[?.\\s]+").splitAsStream(message.toLowerCase()) .filter(w -> w.length() > 2).count()