In jdk7, case statements accept Strings. I have a scenario where i have to check if a String is present in list of strings and then perform operation.
Case "Car":
syso("nice car");
break;
case "bike":
syso("nice bike");
break;
default:
syso("buy something");
or
if(stringList.contains("Car")){
syso("nice car");
}else if(stringList.contains("bike")){
syso{"nice bike");
}else{
syso{"buy something");
}
Till jdk6 case statements did not support Strings. What can be main advantages of this new feature however the same thing can be implemented using if-else..?