Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Comparable interface' - 5 question(s) found - Order By Newest | ||||
| ||||
Ans. It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Implementing Comparable interface means that the elements of the class are comparable i.e the class provides the implementation of compareTo method that would help comparing the elements. This is usually required if we are planning to sort elements of a collection, If compareTo method is not defined , the sorting class / method could never understand a way to compare its elements in order to sort them. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||