equals(): This method is available in java.lang.Enum class of Java.
Syntax:
boolean java.lang.Enum.equals(Object other)
This method takes one argument of type Object as its parameter. This method returns true if the specified object is equal to this enum constant.
Parameters: One parameter is required for this method.
other: the object to be compared for equality with this object.
Returns: true if the specified object is equal to this enum constant.
Exceptions: NA
Approach
Java
enum Colour {RED, GREEN, GRAY, ORANGE}public class Enumequals {public static void main(String[] args) {System.out.println(Colour.RED.equals(Colour.RED));}}
Output:
true
No comments:
Post a Comment