可能有一个库可以更简单地执行此操作,但是手动执行该操作并不难:
List<Person> allPeople; // your list of all peopleMap<String, List<Person>> map = new HashMap<String, List<Person>>();for (Person person : allPeople) { String key = person.getName(); if (map.get(key) == null) { map.put(key, new ArrayList<Person>()); } map.get(key).add(person);}List<Person> davids = map.get("David");


