【Java】Integer包装类
Integer:对基本数据类型 int 实现包装
方法名称 | 说明 |
public Integer(int value) | 根据 int 值创建 Integer 对象(JDK9以后过时) |
public integer(String s) | 根据 String 值创建 Integer 对象(JDK9以后过时) |
public static Integer valueOf (Int i) | 返回表示指定 int 值的 Integer实例 |
public static Integer valueOf (String s) | 返回一个保存指定值的 Integer 对象 String |
示例代码
package com.api.Demo07;public class Test14 {public static void main(String[] args) {// jdk9 开始 不推荐 new Integer(30) new Integer("30")Integer a = new Integer(30);Integer b = new Integer("30");//通过有参构造方法 传递字符串,字符串类型转成 Integer(前提:该字符串里内容确定是整数数字)System.out.println(a);System.out.println(b);System.out.println("=============================");Integer c = Integer.valueOf(30);Integer d = Integer.valueOf("30");System.out.println(c);System.out.println(d);}
}
下一篇文章:Int/boolean/...转String && String转Int/boolean/...