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
     * 
     */

}

}

Author: Susheel kumar

Leave a Reply

Your email address will not be published. Required fields are marked *