Skip to main content

Checkpoint: Contact Book

beginner50 min readLesson 47 of 180

Sets, maps, records, and case-insensitive lookups composing into one small address book.

The Contact Book — collections composing.

Inside Solution, using collections throughout:

  1. static java.util.List<String> sortedUnique(java.util.List<String> raw) — distinct names, case-insensitively, returned ALPHABETICALLY (lowercase order); keep the lowercase form in the result.
  2. static java.util.Map<Character, Integer> initialCounts(java.util.List<String> names) — map from first letter (lowercase) to how many names start with it.
  3. record Contact(String name, java.util.List<String> phones) { } with a compact constructor rejecting blank names; and static String findPhone(java.util.List<Contact> contacts, String name) — case-insensitive lookup returning the FIRST phone of the matching contact, null when the name is unknown.