Question 206 / 297:  What is the result of compiling and running the following code?
import java.util.SortedMap;

import java.util.TreeMap;

public class Test {

public static void main(String[] args) {

TreeMap<Integer,String> map = new TreeMap<Integer,String>();

map.put(1, "one");

map.put(2, "two");

map.put(3, "three");

map.put(4, "four");

SortedMap<Integer, String> smap1 = map.tailMap(2);

SortedMap<Integer, String> smap2 = smap1.headMap(4);

SortedMap<Integer, String> smap3 = smap2.subMap(2, 3);

System.out.println(smap3);

}

}

A  {2=two, 3=three, 4=four}
B  {2=two, 3=three}
C  {2=two}
D  no output is printed
<< First < Previous Next > Last >>
Explanation:

tailMap: returns a view of the portion of this map whose keys are greater than (or equal to, if is true) to the given key.

headMap: returns a view of the portion of this map whose keys are less than (or equal to, if is true) to the given key.

subMap: returns a view of the portion of this map whose keys range from to (where to value is exclusive).

Exam Home Page
Ask
Marion Cabalfin
Start Test
Edgar Delgado
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>