当前位置: 编程技术>java/j2ee
JAVA包装类及自动封包解包实例代码
来源: 互联网 发布时间:2014-10-23
本文导语: 代码如下:public class Wrapper { public static void main(String[] args) { int i = 500; Integer t = new Integer(i); int j = t.intValue(); String s = t.toString(); System.out.println(t); Integ...
代码如下:
public class Wrapper {
public static void main(String[] args) {
int i = 500;
Integer t = new Integer(i);
int j = t.intValue();
String s = t.toString();
System.out.println(t);
Integer t1 = new Integer(500);
System.out.println(t.equals(t1));
Integer a1 = 5;
int a2 = new Integer(5);
System.out.println("a1 = " + a1 + ",a2 = " + a2);
}
}
结果:
D:javacode>javac Wrapper.java
D:javacode>java Wrapper
500
true
a1 = 5,a2 = 5