枚举类型
修饰词:enum
枚举类中不能有方法和成员属性
枚举类型中是由一组常量组成,常量为字符串时,不能加双引号,直接写即可
枚举类型中的常量不能是基本数据类型,比如数字,小写的true或false
枚举类中的多个值使用英文逗号分隔
包装类:
案例分析:
String flagStr = "tru";
Boolean flagBool = new Boolean(flagStr);
System.out.println("flagBool = " + flagBool);
将字符串转换为布尔类型的包装类时,不区分大小写,并且只要字符串内容不是true,那么转换结果都是false
将字符串转换为包装类:
注意:字符串中的真实数据的类型必须符合包装类对应的基本数据类型
方式一:构造方法
Integer a = new Integer("1001");
方式二:valueOf方法
Integer a1 = Integer.valueOf("1002");
将基本数据类型转换为包装类:(装箱)
方式一:构造方法
Integer a = new Integer(1011);
方式二:valueOf方法
Integer a1 = Integer.valueOf(102);
方式三:简写/自动完成
int x = 1012;
Integer xInt =x;
将包装类转换为基本数据类:(拆箱)
方式一:XXXValue方法
Integer aNumInt = new Integer("1008");
int aNum = aNumInt.intValue();
Double bNumDouble = new Double("1008.15");
double bNum = bNumDouble.doubleValue();
System.out.println(bNum);
方式二:简写/自动完成
Integer yInt = 4512;
int y = yInt;
将字符串内容转换为基本数据类型:
注意:若转换为数字,则要求字符串内容不能超出目标类型的取值范围
parseXXX方法
String s1 = "1009";
String s2 = "1009.564";
String s3 = "TrUe";
int as1 = Integer.parseInt(s1);
double bs2 = Double.parseDouble(s2);
boolean cs3 = Boolean.parseBoolean(s3);