Discussion
What will be the output of the program?
import java.util.*;
public class Trial43
{
public static void main(String[] args)
{
List<Integer> scores = new ArrayList<Integer>(
Arrays.asList(70, 95, 82));
Collections.sort(scores, Collections.reverseOrder());
int top = scores.get(0);
Collections.sort(scores);
System.out.println(top + " " + scores.get(0) + " " + scores);
}
}
Answer: C
reverseOrder returns a comparator that inverts the natural ordering, so the first sort puts the highest score first and top reads 95. Sorting again without a comparator restores ascending order, so the same position now holds 70. Each sort rearranges the list in place; nothing is returned.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development