Oracle
1Z0-851 · Question #169
Given: 01. import java.util.*; 02. public class Example { 03. public static void main(String[] args) { 04. // insert code here 05. set.add(new Integer(2)); 06. set.add(new Integer(1)); 07…
The correct answer is A. Set set = new TreeSet(). See the full explanation below for the reasoning.
Question
Given: 01. import java.util.*; 02. public class Example { 03. public static void main(String[] args) { 04. // insert code here 05. set.add(new Integer(2)); 06. set.add(new Integer(1)); 07. System.out.println(set); 08. } 09. } Which code, inserted at line 4, guarantees that this program will output [1, 2]?
Options
- ASet set = new TreeSet();
- BSet set = new HashSet();
- CSet set = new SortedSet();
- DList set = new SortedList();
- ESet set = new LinkedHashSet();
How the community answered
(65 responses)- A72% (47)
- B2% (1)
- C15% (10)
- D8% (5)
- E3% (2)
Community Discussion
No community discussion yet for this question.