Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. 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. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   comparable interface Asked in 7 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   comparable interface   treemap   compareto | ||||
| ||||
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   comparable interface   treemap | ||||
| ||||
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   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. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  comparable interface | ||||
Try 1 Question(s) Test | ||||