Oracle
1Z0-851 · Question #7
Given: import java.util.*; public class SortOf { public static void main(String[] args) { ArrayList<Integer> a = new ArrayList<Integer>(); a.add(1); a.add(5); a.add(3); Collections.sort(a)…
The correct answer is C. [2, 5, 3, 1]. See the full explanation below for the reasoning.
Question
Given: import java.util.*; public class SortOf { public static void main(String[] args) { ArrayList<Integer> a = new ArrayList<Integer>(); a.add(1); a.add(5); a.add(3); Collections.sort(a); a.add(2); Collections.reverse(a); System.out.println(a); } } What is the result?
Options
- A[1, 2, 3, 5]
- B[2, 1, 3, 5]
- C[2, 5, 3, 1]
- D[5, 3, 2, 1]
- E[1, 3, 5, 2]
- FCompilation fails.
- HAn exception is thrown at runtime.
How the community answered
(40 responses)- B8% (3)
- C85% (34)
- D3% (1)
- E3% (1)
- H3% (1)
Community Discussion
No community discussion yet for this question.