Which code, inserted at line 4, guarantees that this program will output [1, 2]?

Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
8. }
9. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?

Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
8. }
9. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?

A.
Set set = new HashSet();

B.
List set = new SortedList();

C.
Set set = new TreeSet();

D.
Set set = new LinkedHashSet();

E.
Set set = new SortedSet();

Explanation:



Leave a Reply 0

Your email address will not be published. Required fields are marked *