1.代码实现: import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class ListUtilEme { public static Map<String,Integer> frequencyOfListElements(List<String> items ) { if (items == null || items.size() == 0) return null; Map<String, Integer> map = new HashMap<String, Integer>(); for (String temp : items) { Integer count = map.get(temp); map.put(temp, (count == null) ? 1 : count + 1); } return map; } public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("aa"); list.add("bb"); list.add("bb"); Map<String,Integer> map = ListUtilEme.frequencyOfListElements(list); for(String key: map.keySet()){ System.out.println(key+":"+map.get(key)); } } } 2.代码运行图: