Friday 2 May 2014

Enum : equals : Check for equality

public final boolean equals(Object other)
Returns true if the specified object is equal to this enum constant.

enum Day{
 MON,
 TUE,
 WED,
 THU,
 FRI,
 SAT,
 SUN;
 
 public static void main(String args[]){
  System.out.println("\tMON\tTUE\tWED\tTHU\tFRI\tSAT\tSUN");
  
  for(Day d1 : Day.values()){
   System.out.print(d1 +"\t");
   for(Day d2 : Day.values()){
    System.out.print(d1.equals(d2)+" \t");
   }
   System.out.println();
  }
 }
}

Output
        MON     TUE     WED     THU     FRI     SAT     SUN
MON     true    false   false   false   false   false   false
TUE     false   true    false   false   false   false   false
WED     false   false   true    false   false   false   false
THU     false   false   false   true    false   false   false
FRI     false   false   false   false   true    false   false
SAT     false   false   false   false   false   true    false
SUN     false   false   false   false   false   false   true



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment