treemap navigablekeyset 28 29 method in java

Solutions on MaxInterview for treemap navigablekeyset 28 29 method in java by the best coders in the world

showing results for - "treemap navigablekeyset 28 29 method in java"
Sylvester
31 Apr 2020
1import java.util.NavigableSet;
2import java.util.TreeMap;
3public class TreeMapNavigableKeySetMethodExample
4{
5   public static void main(String[] args)
6   {
7      try
8      {
9         TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
10         tm.put("apple", 11);
11         tm.put("banana", 12);
12         tm.put("grapes", 13);
13         tm.put("orange", 14);
14         tm.put("pineapple", 15);
15         System.out.println("Given TreeMap: " + tm);
16         // get NavigableSet view of keys using navigableKeySet() method
17         NavigableSet<String> ns = tm.navigableKeySet();
18         System.out.println("Value is: " + ns);
19      }
20      catch(NullPointerException ex)
21      {
22         System.out.println("Exception: " + ex);
23      }
24   }
25}
Tom
12 Apr 2019
1import java.util.NavigableSet;
2import java.util.TreeMap;
3public class TreeMapNavigableKeySetMethodExample
4{
5   public static void main(String[] args)
6   {
7      try
8      {
9         TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
10         tm.put(11, "apple");
11         tm.put(12, "banana");
12         tm.put(13, "grapes");
13         tm.put(14, "orange");
14         tm.put(15, "pineapple");
15         System.out.println("Given TreeMap: " + tm);
16         // get NavigableSet view of keys using navigableKeySet() method
17         NavigableSet<Integer> ns = tm.navigableKeySet();
18         System.out.println("Value is: " + ns);
19      }
20      catch(NullPointerException ex)
21      {
22         System.out.println("Exception: " + ex);
23      }
24   }
25}