Friday 2 May 2014

Enum : name : Get the name Of enum constant

public final String name()
Returns the name of this enum constant, exactly as declared in its enum declaration.

enum Day{
 MON,
 TUE,
 WED,
 THU,
 FRI,
 SAT,
 SUN;
 
 public static void main(String args[]){
  for(Day d1 : Day.values()){
   System.out.print("Name for " + d1 + " is ");
   System.out.println(d1.name());
  }
 }
}

Output
Name for MON is MON
Name for TUE is TUE
Name for WED is WED
Name for THU is THU
Name for FRI is FRI
Name for SAT is SAT
Name for SUN is SUN




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment