Discussion
Which of these statements about what Collections.sort requires of the elements it is given is correct?
Answer: D
Correct answer: Either the elements implement Comparable, or a Comparator is supplied.
Collections.sort is overloaded: the one-argument form requires the elements’ natural ordering and throws ClassCastException if they do not implement Comparable, while the two-argument form takes a Comparator and imposes no requirement on the elements at all. Sorting neither copies the list nor consults equals, so Cloneable and the equals contract are irrelevant here.
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