Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public static void groupByLastNameOldWay(List<Person> people) {
  2.     //before Guava - 9 lines
  3.     Map<String, Collection<Person>> peopleForLastName = new HashMap<String, Collection<Person>>();
  4.     for (Person p : people) {
  5.       List<Person> peopleWithLastName = peopleForLastName.get(p.getLast());
  6.       if (peopleWithLastName == null) {
  7.         peopleWithLastName = new ArrayList<Person>();
  8.         peopleForLastName.put(p.getLast(), peopleWithLastName);
  9.       }
  10.       peopleWithLastName.add(p);
  11.     }
  12.     //peopleForLastName.get("Smith") will return Collection<Person>
  13. }