I\'m trying to group Java objects by their field, i.e Person.java
public class Person {
String name;
String surname;
....
}
There's probably a library that can do this more simply, but it's not too hard to do it manually:
List allPeople; // your list of all people
Map> map = new HashMap>();
for (Person person : allPeople) {
String key = person.getName();
if (map.get(key) == null) {
map.put(key, new ArrayList());
}
map.get(key).add(person);
}
List davids = map.get("David");