*高级API
java.lang.* : java基础包,一般不需要导入包.
java.util.* : java工具包
java.io.*: java数据读写包
*java.lang.*
Integer:该类还提供了一些将int转换为String和String转换为int ,以及在处理int时有用的其他常量和方法.
1. int -> Integer
Integer it1 = new Integer(15);
Integer it3 = Integer.valueOf(22);
2. String -> Integer
Integer it2 = new Integer("20");
Integer it4 = Integer.valueOf("30");
3. Integer -> int
int value = it1.intValue();
4.String -> int
int number = Integer.parseInt("16",8);
5.Integer -> String
String str = it1.toString();
6.int -> String
String str2 = Integer.toString(18,8); //"18"
String str3 = String.valueOf(111);
重点 Java中的`Boolean(java.lang.String)`构造函数已经被弃用,并在Java 8中正式移除。从Java 9开始,如果你需要将字符串转换为布尔值,可以使用`java.lang.Boolean.parseBoolean()`方法也可以用Boolean.value.Of()。
自动拆、装箱
自动装箱:
Integer i = 18;编译器会自动把基本类型int 18 包装成包装类型Integer,然后交给Integer的类型的变量来保存,底层发生的代码实际是:Integer.valueOf(18); 自动装箱的方向 int【基本类型】 => Integer【包装类型】
自动拆箱:
int i1 = i;编译器会自动把包装类型i拆掉“箱子”,变回基本类型的数据18,然后交给基本类型的变量i1来保存,底层代码:int i1 = i.intValue();,自动拆箱的方向:Integer【包装类型】 => int【基本类型】