Home Tutorial Java Scjp Part9 SCJP Module-9 Question-3

 
 

SCJP Module-9 Question-3
Posted on: July 16, 2010 at 12:00 AM
The Sample program given below will check your knowledge of Collection framework in Java.

Given below the sample code :

import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
public class CheckSize {
public static void main(String... args) {
NavigableMap <Integer, String>nM = new ConcurrentSkipListMap<Integer, String>();
nM.put(4, "Wednesday");
nM.put(5, "Thursday");
nM.put(6, "Friday");
nM.put(1, "Sunday");
nM.put(2, "Monday");
nM.put(3, "Tuesday");
nM.pollFirstEntry();
nM.pollLastEntry();
nM.pollFirstEntry();
nM.pollLastEntry();
System.out.println(nM.size());
}
}

What will be the output of the above code ?

1. Compile error

2. 6

3. 3

4. 2

Answer

(4)

Explanation

pollFirstEntry()   It Removes the element and returns a key-value mapping
associated with the least key in this map, or null if the map is empty.

pollLastEntry()   It Removes the element and returns a key-value mapping
associated with the greatest key in this map, or null ifthe map is empty.

Related Tags for SCJP Module-9 Question-3:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.