Beispiel mit einer NavigableMap:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | NavigableMap<String, String> navigableMap = new TreeMap<>(); navigableMap.put("A", "Ava"); navigableMap.put("B", "Benny"); navigableMap.put("C", "Clara"); navigableMap.put("D", "Daniel"); navigableMap.put("E", "Erina"); String from = "A"; String to = "C"; boolean inclusive = true; NavigableMap<String, String> searchResults = navigableMap.subMap("A", inclusive, "C", inclusive); for (String key : searchResults.keySet()) { System.out.println(searchResults.get(key)); // Ava, Benny, Erina } |