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

 
 

SCJP Module-9 Question-3
Posted on: July 16, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-9 Question-3:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com