SCJP Module-9 Question-16


 

SCJP Module-9 Question-16

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

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)

Ads