Multiple choice

What is/are the difference(s) between comparator and comparable in Java?

  1. Comparator is present in java.Util package and Comparable is present in java.lang Package.

  2. Comparator consists of int Compare(Object o1, Object o2)and Comparable consists of int CompareTo(Object o).

  3. In case of Comparable Sorting, logic must be in the same class whose objects are to be sorted whereas in case of Comparator sorting, logic is in separate class.

  4. All of the above.

  5. None of these

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

All the statements are true.