Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
Java
|
TreeMap
Notes
Example
Notes
Sorted entries
Duplicates elements not allowed
Example
TreeMap<Integer, String> tm = new TreeMap<>(); tm.clear(); // tm.put(null, "x"); // java.lang.NullPointerException // tm.put(0, null); // OK tm.put(0, "a"); tm.put(4444, "c"); tm.put(55555, "b"); tm.put(333, "d"); tm.put(11, "f"); tm.put(222, "e"); tm.put(666666, "g"); for (Map.Entry<Integer, String> entry : tm.entrySet()) { System.out.println(entry.getKey() + " = " + entry.getValue()); }
Output:
0 = a 11 = f 222 = e 3333 = d 44444 = c 555555 = b 6666666 = g
© 2010-2022
mti
tek