A long overdue and seemingly basic feature but better late than never. So now Java has the feature which dotNet had earlier.
public class StringsInSwitch {
public static void main(String[] args) {
for (String a : new String[]{"foo", "bar", "baz"}) {
switch (a) {
case "foo":
System.out.println("received foo!");
break;
case "bar":
System.out.println("received bar!");
break;
case "baz":
System.out.println("received baz!");
break;
}
}
}
}
No comments:
Post a Comment