CompositeName compareTo() method in Java with Examples
The compareTo() method of a javax.naming.CompositeName class is used to compare this CompositeName with the specified object passed as a parameter. It returns a negative integer, zero, or a positive integer as this CompositeName is less than, equal to, or greater than the given Object as a parameter. If the passed object is null or not an instance of CompositeName then the ClassCastException is thrown by this method.
public int compareTo(Object obj)
Parameters: This method accepts obj which is the non-null object to compare against.
Return value: This method returns a negative integer, zero, or a positive integer as this Name is less than, equal to, or greater than the given Object.
This method throw ClassCastException if obj is not a CompositeName.
Below programs illustrate the CompositeName.compareTo() method:
CompositeName1 is smaller than CompositeName2
CompositeName1 is greater than CompositeName2
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.