There is no way to perform a true switch on a String in Java. With the arrival of JDK 5.0 and its implementation of enum
, a reasonably close approximation of this can be done using the following code.
Create an enum :
public enum Months{ JAN, FEB, MAR, APRIL;}
Continue reading “Use of String variable in Java Switch Statement”