1.包装类 java.lang
两个概念: 装箱、拆箱
8个包装类 | 基本数据类型 |
---|---|
Integer | int |
Short | short |
Byte | byte |
Long | long |
Float | float |
Double | double |
Boolean | boolean |
Character | char |
- Integer.MAX_VALUE:获取int类型的取值范围的最大值 -2147483648 - 2147483647
- Integer.MIN_VALUE:获取int类型的取值范围的最小值:-2147483648 ----- 2147483647
- Integer.SIZE:获取int类型的byte位数 :32 (位) 4(个字节)
- Integer.TPYE:获取Integer的基本数据类型int
包装类的作用:用于弥补基本数据类型没有方法而产生的
1.1 装箱
int a = 1; //基本数据类型
Integer b = a; //这个就叫装箱
int c = b; //这个就叫拆箱
//区别: 装箱之后就能使用方法, 拆箱之后就无法使用方法了
包装类 跟 String很像 :都是将初始化的数据放在常量池中
Integer a=1;
Integer b=1;
Integer c=a;
//此时,a b c都是在栈中,指向常量池中唯一的地址
Integer b=2;
2.正则表达式
是一个字符串的规范
例: 2019-04-20 0?[1-9](从0-9中间随便找一个数字)
正则表达式:
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])$
代码:
Scanner sc = new Scanner(System.in);
String regex = "^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])$";
boolean matches = Pattern.matches(regex, sc.next());
System.out.println(matches);
2.2 正则表达式规则:
(1) 是(?=人) 表示 人 的相邻的前面必须是 是 才能匹配
(2) (?<=人)… 表示 必须是 人开头 才能匹配
(3) …(?<=人) 表示 必须是 人 结尾 才能匹配