Write a function that returns the closest chapter to the current page you are at. If two chapters are similarly close, return whichever has the higher page.
closestToPage(new ArrayList<Map.Entry<String, Integer> >(
Arrays.asList(
new SimpleEntry<String, Integer>("Chapter 1", 1),
new SimpleEntry<String, Integer>("Chapter 2", 15),
new SimpleEntry<String, Integer>("Chapter 3", 37)
)), 10) ➞ "Chapter 2"
closestToPage(new ArrayList<Map.Entry<String, Integer> >(
Arrays.asList(
new SimpleEntry<String, Integer>("Chapter 1", 1),
new SimpleEntry<String, Integer>("Chapter 2", 15),
new SimpleEntry<String, Integer>("Chapter 3", 37)
)), 200) ➞ "The End?"
closestToPage(new ArrayList<Map.Entry<String, Integer> >(
Arrays.asList(
new SimpleEntry<String, Integer>("Chapter 1a", 1),
new SimpleEntry<String, Integer>("Chapter 1b", 5)
)), 3) ➞ "Chapter 1b"Map.Entryand SimpleEntry classes in lieu to Map and HashMap.classes instead of Map-types can be found via this link.