treemap headmap 28 29 method in java

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

showing results for - "treemap headmap 28 29 method in java"
Anna
03 Jan 2018
1import java.util.SortedMap;
2import java.util.TreeMap;
3public class TreeMapHeadMapMethodExample
4{
5   public static void main(String[] args)
6   {
7      TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
8      // map string values to integer keys
9      tm.put("mango", 65);
10      tm.put("apple", 63);
11      tm.put("grapes", 35);
12      tm.put("pineapple", 60);
13      tm.put("banana", 26);
14      System.out.println("Given TreeMap is: " + tm);
15      // create SortedMap for map head
16      SortedMap<String, Integer> sm = new TreeMap<String, Integer>();
17      sm = tm.headMap("pineapple");
18      // Getting map head
19      System.out.println("headmap is: " + sm);
20   }
21}
Giorgia
08 Mar 2018
1import java.util.SortedMap;
2import java.util.TreeMap;
3public class TreeMapHeadMapMethodExample
4{
5   public static void main(String[] args)
6   {
7      TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
8      // map string values to integer keys
9      tm.put(65, "mango");
10      tm.put(63, "apple");
11      tm.put(35, "grapes");
12      tm.put(60, "pineapple");
13      tm.put(26, "banana");
14      System.out.println("Given TreeMap is: " + tm);
15      // create SortedMap for map head
16      SortedMap<Integer, String> sm = new TreeMap<Integer, String>();
17      sm = tm.headMap(60);
18      // Getting map head
19      System.out.println("headmap is: " + sm);
20   }
21}