Warning: Undefined array key "amp-addthis" in /home/tgagmvup/onlinestudy.guru/wp-content/plugins/addthis/backend/AddThisSharingButtonsFeature.php on line 101
lang="en-US"> Difference between int and Integer in java
Site icon onlinestudy.guru

Difference between int and Integer in java

In Java Both int and Integer used to store Integer type data.

int is primitive data type

whereas Integer is a predefined class in java from java.lang.Integer package

public class IntVsInteger {
public static void main(String[] args) {
// primitive data type
int value = 10;
System.out.println(“primitive data type value ” + value);

    // integer is a class create constructor and assign value
    @SuppressWarnings("deprecation")
    Integer value_of_integer_class = new Integer("10");
    System.out.println("Integer class value " + value_of_integer_class);

    /**
     * output is
     * 
     * primitive data type value 10 -------Integer class value 10
     * 
     */

}

}

Exit mobile version