Java基本数据类型-包装类

为什么会有基本数据类型包装类?

  • 将基本数据类型封装成为对象,这样可以在对象中定义更多的方法来操作该数据
  • 包装类常用操作就是用于基本数据类型与字符串之间的转换

基本数据类型对应的包装类

  • byte(Byte)
  • short(Short)
  • int(Integer)
  • long(Long)
  • float(Float)
  • double(Double)
  • char(Character)
  • boolean(Boolean)

不知道包装类有啥用?看这里:

System.out.println(Integer.toBinaryString(10));  //将10转化为二进制输出
System.out.println(Integer.toHexString(17)); //转化为十六进制
System.out.println(Integer.toOctalString(9)); //转化为八进制

猜你喜欢

转载自www.cnblogs.com/smiling-crying/p/9333634.html