public static void main(String[] args) { LinkedHashMap<Integer, String> hashmap = new LinkedHashMap<Integer, String>(); hashmap.put(1, "apple"); hashmap.put(2, "lemon"); hashmap.put(3, "orange"); hashmap.put(4, "banana"); hashmap.put(5, "litchi"); hashmap.put(6, "mango"); hashmap.put(7, "papaya"); System.out.println(hashmap); System.out.println(valuesBetween(2, 5, hashmap)); // // note insertion order lost // Map map1 = new HashMap<>(); // //for (int i = 1; i < 15; i++) { // for (int i = 14; i > 0; i--) { // map1.put(String.format("%04d", i), ""); // System.out.println(String.format("%04d:", i) + map1); // } // // map1 = new LinkedHashMap<>(); // //for (int i = 1; i < 15; i++) { // for (int i = 14; i > 0; i--) { // map1.put(String.format("%04d", i), ""); // System.out.println(String.format("%04d:", i) + map1); // } Map<String, String> myMap = new HashMap<>(); myMap.put("A", "1"); myMap.put("B", "1"); myMap.put("C", "1"); System.out.println(myMap); myMap = new LinkedHashMap<>(); myMap.put("A", "1"); myMap.put("C", "1"); myMap.put("B", "1"); NavigableMap<Integer, String> map = new TreeMap<Integer, String>(); map.put(0, "Kid"); map.put(11, "Teens"); map.put(20, "Twenties"); map.put(30, "Thirties"); map.put(40, "Forties"); map.put(50, "Senior"); map.put(100, "OMG OMG OMG!"); System.out.println(map.get(map.floorKey(13))); System.out.println(map.get(map.higherKey(20))); }
/** * {@inheritDoc} * * @see java.util.NavigableSet#higher(java.lang.Object) * @since 1.6 */ public E higher(E e) { return backingMap.higherKey(e); }
/** * @throws ClassCastException {@inheritDoc} * @throws NullPointerException if the specified element is null and this set uses natural * ordering, or its comparator does not permit null elements * @since 1.6 */ public E higher(E e) { return m.higherKey(e); }