如何将我的方法 return 改为 Collection<Character>

How to make my method return a Collection<Character> instead

我的方法应该被调用

Public Collection<Character> mostCommonFirstWeighted()

但是我解决问题的方法是return

List<Map.Entry<Character, Integer>>

如何解决此问题,使我的 return 语句变成字符集合?

    public List<Map.Entry<Character, Integer>> mostCommonFirstWeighted() {
        HashMap<Character, Integer> hashmap = new HashMap<Character, Integer>();
        for (String s : lst) {
            if (hashmap.get(s.charAt(0)) == null) {
                hashmap.put(s.charAt(0), 1);
            } else {
                hashmap.put(s.charAt(0), hashmap.get(s.charAt(0)).intValue() + 1);
            }
        }
        Integer largestVal = null;
        List<Map.Entry<Character, Integer>> largestList = new ArrayList<Map.Entry<Character, Integer>>();
        for (Map.Entry<Character, Integer> i : hashmap.entrySet()) {
            if (largestVal == null || largestVal < i.getValue()) {
                largestVal = i.getValue();
                largestList.clear();
                largestList.add(i);
            } else if (largestVal == i.getValue()) {
                largestList.add(i);
            }
        }
        return largestList;
    }

}

示例输入:[and, and, and, and, these, those, their, boxes, boxes]

预期结果:[a]

我得到的是:[a=4]

改变

    List<Map.Entry<Character, Integer>> largestList = new ArrayList<Map.Entry<Character, Integer>>();

    List<Character> largestList = new ArrayList<Character>();

largestList.add(i);(两者)到largestList.add(i.getKey());