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:
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.static java.util.Map<Character, Integer> initialCounts(java.util.List<String> names)ā map from first letter (lowercase) to how many names start with it.record Contact(String name, java.util.List<String> phones) { }with a compact constructor rejecting blank names; andstatic String findPhone(java.util.List<Contact> contacts, String name)ā case-insensitive lookup returning the FIRST phone of the matching contact,nullwhen the name is unknown.