import java.util.ArrayList;
public class Demo128 {
public static void main(String[] args) {
String str = "12";
//功能一:可以把字符串转成数字
int num = Integer.parseInt(str);
System.out.println(num+1);
//功能2: 可以把数字转成指定进制格式的字符串。
int num2 = 10;
System.out.println("二进制:"+ Integer.toBinaryString(num2));
System.out.println("八进制:"+ Integer.toOctalString(num2));
System.out.println("十六进制:"+ Integer.toHexString(num2));
//自动装箱 -- 自动把基本数据类型转成引用数据类型数据,
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1); // new Integer(数据)
list.add(2);
//自动拆箱: 自动把引用数据类型数据转成 基本数据类型.
Integer i = new Integer(10);//引用数据类型数据
System.out.println(2+i); // intValue() 获取基本类型的数据
Integer i1 = 127;
Integer i2 = 127;
Integer i3 = 128;
Integer i4 = 128;
System.out.println("是同一个对象 吗?"+(i1==i2));
System.out.println("是同一个对象 吗?"+(i3==i4));
}
}
JAVA小练习128——包装类的练习
猜你喜欢
转载自blog.csdn.net/Eric_The_Red/article/details/91834016
今日推荐
周排行