Java学习笔记——包装类

包装类

由于基本数据类型的数据没有相应方法进行操作,使用一个类对基本数据类型进行包装增强。

装箱

  1. 构造方法

​ new Integer(int)

​ new Integer(“10”)

  1. 静态方法

​ valueof(int)

​ valueof(“10”)

拆箱

​ .intvalue()

自动拆装箱

Integer in = 10;自动装箱为Integer
in+=2;拆箱进行计算,再进行装箱为Integer

基本数据类型与string

基本数据类型–>string

​ 123+""

string–>基本数据类型

​ parsexx(str)

string与stringbuilder转换

sting与stringbuilder转换

  • str->strb:创建strb的构造方法
  • strb->str:strb.tostring()

你可能感兴趣的:(Java,java,开发语言,后端)