SCJP Module-9 Question-16

The Sample code given below will test your understanding of Collection framework of Java.

 
 

Share on Google+Share on Google+

SCJP Module-9 Question-16

Ads

The Sample code given below will test your understanding of Collection framework of Java.

Given below the sample code :

1.  import java.util.*;
2.  public class Demo {
3.  public static void main(String[] args) {
4.  // insert code here
5.  t.add(new Integer(2));
6.  t.add(new Integer(1));
7.  System.out.println(t);
8.  }
9.  }

Which line given below should place at line 4 to give output [1, 2] , by the above code?

1. Set set = new LinkedHashSet();

2. Set set = new SortedSet();

3. Set set = new HashSet();

4. Set set = new TreeSet();

Answer

(4)

Advertisements

Posted on: July 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles