What will be the result of compilation and execution of the following code:

 1. import java.util.*;                                                  
 2. 
 3. class SomeClass {                                                 
 4.   public static void main(String[] args) {                           
 5.     TreeMap<String, Integer> myMap = new TreeMap<String, Integer>(); 
 6.     myMap.put("a", 50);  myMap.put("b", 60);                       
 7.     myMap.put("c", 70);  
 8.     NavigableMap<String, Integer> myMap2 = myMap.headMap("d", true);
 9.     myMap.put("e", 90);                                            
10.     myMap2.put("f", 100);                                          
11.     System.out.println(myMap.size() + " " + myMap2.size());         
12.   }                                                                 
13. }
Explanation
Exception in thread "main" java.lang.IllegalArgumentException: key out of range at java.util.TreeMap$NavigableSubMap.put(TreeMap.java:1407) at SomeClass.main(SomeClass.java:10)
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback