How to Count Repetition of Words in Array List?

后端 未结 5 888
醉话见心
醉话见心 2020-12-22 08:04

I\'ve these code for searching occurrence in Array-List but my problem is how I can get result out side of this for loop in integer type cause I need in out side , may be th

5条回答
  •  我在风中等你
    2020-12-22 08:25

    You should declare a map like Map countMap = new HashMap(); before the loop, and populate it within the loop.

    Map countMap = new HashMap();
    for (String key : unique) {
        int accurNO = Collections.frequency(list, key);
        coutMap.put(key, accurNO);
        //...
    }
    //now you have a map with keys and their frequencies in the list
    

提交回复
热议问题