How to Count Repetition of Words in Array List?

后端 未结 5 876
醉话见心
醉话见心 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:41

    List list = new ArrayList();
    list.add("aaa");
    list.add("bbb");
    list.add("aaa");
    Map countMap = new HashMap();
    
    Set unique = new HashSet(list);
    for (String key : unique) {
      int accurNO = Collections.frequency(list, key);
      countMap.put(key,accurNO);
      System.out.println(key + ": " accurNO);
    }
    

提交回复
热议问题