Calculating frequency of each word in a sentence in java

前端 未结 19 2132
夕颜
夕颜 2020-11-29 10:15

I am writing a very basic java program that calculates frequency of each word in a sentence so far i managed to do this much

import java.io.*;

class Linked         


        
19条回答
  •  猫巷女王i
    2020-11-29 11:01

    Count frequency of elements of list in java 8

    List list = new ArrayList();
    Collections.addAll(list,3,6,3,8,4,9,3,6,9,4,8,3,7,2);
    Map frequencyMap = list.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting()));
    
        System.out.println(frequencyMap);
    

    Note : For String frequency counting split the string and convert it to list and use streams for count frequency => (Map frequencyMap)*

    Check below link

提交回复
热议问题