Integer
Integer构造方法
- new Integer(int number)
- new Integer(String str)
以上有两种方式获取 Integer对象
Integer常量
Integer.MAX_VALUE 返回int型的最大值
Integer.MIN_VALUE 返回int型的最小值
Integer.SIZE 用二进制补码形式表示 int位数
Integer.TYPE 基本类型int
public static void main(String[] args) {
System.out.println("int最大值(max):"+Integer.MAX_VALUE);
System.out.println("int最小值(min):"+Integer.MIN_VALUE);
System.out.println("max:"+Integer.SIZE);
System.out.println("max:"+Integer.TYPE);
}
运行结果
int最大值(max):2147483647
int最小值(min):-2147483648
max:32
max:int
Integer方法
Integer.byteValue() 以 byte类型 返回
Integer.compareTo(Integer i) 比较是否相同,两值相同则返回 0,对象小于 参数i 返回负值,否则为正值
Integer.intValue() 以 int类型 返回
Integer.shortValue() 以 short类型 返回
Integer.toString() 返回 Integer值 的 String对象,返回String
Integer.valueOf(String str) 返回保存参数的 Integer对象
Integer.parseInt(String str) 返回参数中的数值
public class no1 {
public static void main(String[] args) {
Integer n = new Integer(12);
System.out.println("byteValue() 以 byte类型 返回(12):"+n.byteValue());
System.out.println("compareTo(Integer i)比较是否相同(12 v 10):"+n.compareTo(10));
System.out.println("intValue()以 int类型 返回:"+n.intValue());
System.out.println("shortValue()以 short类型 返回:"+n.shortValue());
String str = new String("123");
System.out.println("toString()返回 Integer值 的 String对象:"+str.toString());
System.out.println("valueOf(String str) 返回保存参数的 Integer对象((String)123) : "+n.valueOf("123"));
System.out.println("parseInt(String str) 返回参数中的数值((String)123):"+n.parseInt("123"));
}
}
运行结果
byteValue() 以 byte类型 返回(12):12
compareTo(Integer i)比较是否相同(12 v 10):1
intValue()以 int类型 返回:12
shortValue()以 short类型 返回:12
toString()返回 Integer值 的 String对象:123
valueOf(String str) 返回保存参数的 Integer对象((String)123) : 123
parseInt(String str) 返回参数中的数值((String)123):123
Boolean
Boolean构造方法
- new Boolean(boolean value)
- new Boolean(String str)
以上有两种方式获取 Boolean对象
Boolean常量
Boolean.TRUE 对应基于true的 Boolean对象
Boolean.FALSE 对应基于false的 Boolean对象
Boolean.TYPE 基本类型Boolean
public static void main(String[] args) {
System.out.println("Boolean.TRUE:"+Boolean.TRUE);
System.</