java-10包装类

装箱:
将基本数据类型封装为包装类对象,利用每一个包装类提供的构造方法实现装箱操作。
拆箱:
将包装类中包装的基本数据类型数据取出。

// 装箱
Integer integer1 = new Integer(1);
// 拆箱
int integer2 = integer1.intValue(); 

JDK1.5之后提供自动拆装箱。

// 自动装箱
Integer integer1 = 1;
// 自动拆箱
int integer2 = integer1; 

各种类型的包装类:

public class WarpDemo {
 //ctrl+shirt+f  格式化代码
 //alt+/ 内筒辅助
 public static void main(String []args) {
  //@SuppressWarnings("deprecation")
  Byte b=new Byte((byte)12);
  System.out.println(Byte.MAX_VALUE);
  System.out.println(Byte.MIN_VALUE);
Short s=new Short((short)12);
Integer i=new Integer(12);
Long l=new Long(12);
long ll=11L;
float f=12.2f;
Boolean bb=new Boolean(true);
bb.booleanValue();
 }

具体介绍请参考:包装类介绍

发布了50 篇原创文章 · 获赞 75 · 访问量 6687

猜你喜欢

转载自blog.csdn.net/weixin_45822638/article/details/103855546