Use Enum in Switch Statement
--------------------------------enumeration.java-------------------put it in a new file
public enum enumeration {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
------------------------------------------------------------------------
----------------------Test.java---------------------------------
public class Test {
public static void main(String[] args)
{
String s;
s="SUNDAY1";
try{
if(enumeration.valueOf(s) != null)
System.out.print("ya");
}catch(Exception E){System.err.print("Not found "+E);}
}
}
---------------------------------------------------------
No comments:
Post a Comment