一、Integer类的常用方法 valueOf, parseInt, intValue对比
方法名 | 修饰符 | 输入 | 输出 | 用途 | 概括为 |
---|---|---|---|---|---|
valueOf | static | (int i) (String str) | Integer | 生成Integer实例,值为 int i 生成Integer实例,值为String str | 生成对象 |
parseInt | static | (String str) | int | 将 String 转为 int | 类型转换 |
intValue | 非静态 | () | int | 返回 Integer 实例对应的 int 值 | 取出值 |
public static Integer valueOf (int i / String str) //生成实例
public static int parseInt(String str) //转成int
public int intValue() //提取int值
- 自动装箱 == 执行Integer.valueOf( int xx )
- 自动拆箱 == 执行object.intValue()