switch后面的表达式类型

来源:互联网 发布:网站程序员工资 编辑:程序博客网 时间:2024/05/19 23:25

switch后面可以跟什么呢

1 基本数据类型

byte short char int  注意!long数据类型不可以

2 引用数据类型

Enum() jdk1.5以后

string()jdk1.7以后

那么下面使用一个字符串作为参数

class Day03 
{
public static void main(String[] args) 
{
String str = "abc";
switch (str)
{
case "abc":
System.out.println("这是一个字符串");
}


}
}

原创粉丝点击