【问题标题】:In Java, what is difference between 1 and 2 statement Integer and int [duplicate]在Java中,1和2语句Integer和int有什么区别[重复]
【发布时间】:2015-05-31 16:29:17
【问题描述】:

1>Integer ie = Integer.valueOf("45");//给出输出45

2>int ie = Integer.valueof("45");//给出与45相同的输出

//你能告诉我第一个语句和第二个语句的区别吗

3>Integer i3 = Integer.valueOf("70");//输出为70

4>int i3 = Integer.valueOf("70");// 也给出相同的输出

【问题讨论】:

    标签: java


    【解决方案1】:

    在 JAVA 5 Integer 中引入的 Java 中称为 unBoxing 是包装类,它提供 Integer object 以取消装箱为 int 原始数据类型。 Integer 有 static 方法,例如

    static Integer valueOf(int i)
    static Integer valueOf(String s)
    static Integer valueOf(String s, int radix)
    

    其他原始数据类型的类似包装类

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

    【讨论】:

      【解决方案2】:

      第一个查询为您提供ObjectInteger 类型。

      第二个查询给你一个原始类型 int。那将与Integer.valueof("45").intValue() 相同;

      【讨论】:

        猜你喜欢
        • 2015-01-29
        • 1970-01-01
        • 2010-09-05
        • 2011-03-26
        • 1970-01-01
        • 2013-09-21
        • 2010-11-19
        • 2018-08-26
        • 2013-02-02
        相关资源
        最近更新 更多