Home How do I write below code in Java 8 using Stream API?
Reply: 0

How do I write below code in Java 8 using Stream API?

user525
1#
user525 Published in April 21, 2018, 3:06 pm

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;
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.634266 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO