Java Enum compareTo() MethodThe compareTo() method of Enum class compares this enum object with the defined object for order. Enum constants can only be compared to other enum constants of the same type. SyntaxParameterso - It is the enum object that is compared Return ValueThe compareTo() method returns:
Example 1Test it NowOutput: A2 is greater than A1. Example 2Test it NowOutput: Val1= 2 Val2= 1 Val3= 1 Spring is my Fav season amongst all seasons. Example 3Test it NowOutput: Red is greater than red.
Next TopicJava Enum
|