1、格式
switch(表达式) {
case 值1:
case 值2:
语句块2;
break;
}
说明:值1和值2都调用语句块2
2、实例
public static void main(String[] args) {
String s1 = "1";
String s2 = "2";
ArrayList<String> list = new ArrayList<>();
list.add(s1);
list.add(s2);
for (String ss : list) {
switch (ss) {
case "1":
case "2":
System.out.println("语句2 --- case值:"+ss);
break;
default: {
System.out.println("switch");
}
}
}
}
3、输出结果
语句2 --- case值:1
语句2 --- case值:2