| 8 | |
| 9 | public class SortedMapDemo { |
| 10 | public static void main(String[] args) { |
| 11 | TreeMap<Integer,String> sortedMap = |
| 12 | new TreeMap<>(new CountMap(10)); |
| 13 | System.out.println(sortedMap); |
| 14 | Integer low = sortedMap.firstKey(); |
| 15 | Integer high = sortedMap.lastKey(); |
| 16 | System.out.println(low); |
| 17 | System.out.println(high); |
| 18 | Iterator<Integer> it = |
| 19 | sortedMap.keySet().iterator(); |
| 20 | for(int i = 0; i <= 6; i++) { |
| 21 | if(i == 3) low = it.next(); |
| 22 | if(i == 6) high = it.next(); |
| 23 | else it.next(); |
| 24 | } |
| 25 | System.out.println(low); |
| 26 | System.out.println(high); |
| 27 | System.out.println(sortedMap.subMap(low, high)); |
| 28 | System.out.println(sortedMap.headMap(high)); |
| 29 | System.out.println(sortedMap.tailMap(low)); |
| 30 | } |
| 31 | } |
| 32 | /* Output: |
| 33 | {0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0, |