Saturday, August 14, 2010


Courtesy of

This causes the following runtime error:

Exception in thread "main" java.lang.IllegalArgumentException: key out of range
    at java.util.TreeMap$NavigableSubMap.put(
    at Quest.main(

The highest key value of myMap is "d" (line 7). When we try to add a key greater than "d", i.e. "hi", we get the above run-time error. If we would have added a key less than "d", such as "ci", there would be no error.

The output is

6 5

To print the contents of both myMap and myMap2, please note lines 11 through 14


Output will be:

6 5
Keys of myMap: [ak, ar, ca, ci, co, fl]
Values of myMap: [50, 80, 70, 100, 60, 90]
Keys of myMap2: [ak, ar, ca, ci, co]
Values of myMap2: [50, 80, 70, 100, 60]

No comments:

Post a Comment