Java Enum.equals(Object other)

Syntax

Enum.equals(Object other) has the following syntax.

public final boolean equals(Object other)

Example

In the following code shows how to use Enum.equals(Object other) method.


//from   w w  w  . j  a v a 2 s . c  o m
enum Tutorial {  
   HTML, CSS, Java;
}
public class Main { 

   public static void main(String args[]) {
     Tutorial t1 = Tutorial.HTML; 
     Tutorial t2 = Tutorial.CSS; 
     Tutorial t3 = Tutorial.Java; 
    
     if(t1.equals(t2)) {
        System.out.println(t1 + " is equal to " + t2); 
     }
    
     else if(t2.equals(t3)) {
        System.out.println(t2 + " is equal to " + t3); 
     }
    
     else if(t1.equals(t3)) { 
        System.out.println(t1 + " is equal to " + t3); 
     }
    
     else {
        System.out.println("all 3 topics are different"); 
     }
   } 
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable