<p>I was reading <em><a href="https://rads.stackoverflow.com/amzn/click/com/1430209879" rel="noreferrer" rel="nofollow noreferrer">More Joel on Software</a></em> when I came across <a href="http://en.wikipedia.org/wiki/Joel_Spolsky" rel="noreferrer">Joel Spolsky</a> saying something about a particular type of programmer knowing the difference between an <code>int</code> and an <code>Integer</code> in Java/C# (Object-Oriented Programming Languages).</p>

<p>So, what is the difference?</p>

[{'answer_id': 566, 'author': 'Matt', 'author_id': 154, 'author_profile': 'https://Stackoverflow.com/users/154', 'pm_score': 9, 'selected': True, 'text': '<p><strong>In Java,</strong> the \'int\' type is a primitive, whereas the \'Integer\' type is an object.</p>\n\n<p><strong>In C#,</strong> the \'int\' type is the same as <code>System.Int32</code> and is <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/value-types" rel="noreferrer">a value type</a> (ie more like the java \'int\'). An integer (just like any other value types) can be <a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxing" rel="noreferrer">boxed</a> ("wrapped") into an object. </p>\n\n<hr>\n\n<p>The differences between objects and primitives are somewhat beyond the scope of this question, but to summarize: </p>\n\n<p><strong>Objects</strong> provide facilities for polymorphism, are passed by reference (or more accurately have references passed by value), and are allocated from the <a href="http://en.wikipedia.org/wiki/Dynamic_memory_allocation" rel="noreferrer">heap</a>. Conversely, <strong>primitives</strong> are immutable types that are passed by value and are often allocated from the <a href="https://en.wikipedia.org/wiki/Stack-based_memory_allocation" rel="noreferrer">stack</a>.</p>\n'}, {'answer_id': 568, 'author': 'cmcculloh', 'author_id': 58, 'author_profile': 'https://Stackoverflow.com/users/58', 'pm_score': 7, 'selected': False, 'text': '<p>Well, in Java an int is a primitive while an Integer is an Object. Meaning, if you made a new Integer:</p>\n\n<pre><code>Integer i = new Integer(6);\n</code></pre>\n\n<p>You could call some method on i:</p>\n\n<pre><code>String s = i.toString();//sets s the string representation of i\n</code></pre>\n\n<p>Whereas with an int:</p>\n\n<pre><code>int i = 6;\n</code></pre>\n\n<p>You cannot call any methods on it, because it is simply a primitive. So:</p>\n\n<pre><code>String s = i.toString();//will not work!!!\n</code></pre>\n\n<p>would produce an error, because int is not an object.</p>\n\n<p>int is one of the few primitives in Java (along with char and some others). I\'m not 100% sure, but I\'m thinking that the Integer object more or less just has an int property and a whole bunch of methods to interact with that property (like the toString() method for example). So Integer is a fancy way to work with an int (Just as perhaps String is a fancy way to work with a group of chars).</p>\n\n<p>I know that Java isn\'t C, but since I\'ve never programmed in C this is the closest I could come to the answer. Hope this helps!</p>\n\n<p><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html" rel="noreferrer">Integer object javadoc</a></p>\n\n<p><a href="http://mindprod.com/jgloss/intvsinteger.html" rel="noreferrer">Integer Ojbect vs. int primitive comparison</a></p>\n'}, {'answer_id': 583, 'author': 'huseyint', 'author_id': 39, 'author_profile': 'https://Stackoverflow.com/users/39', 'pm_score': 4, 'selected': False, 'text': "<p>In C#, int is just an <strong><em>alias</em></strong> for <code>System.Int32</code>, string for <code>System.String</code>, double for <code>System.Double</code> etc...</p>\n\n<p>Personally I prefer int, string, double, etc. because they don't require a <code>using System;</code> statement :) A silly reason, I know...</p>\n"}, {'answer_id': 608, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 5, 'selected': False, 'text': "<p>I'll add to the excellent answers given above, and talk about boxing and unboxing, and how this applies to Java (although C# has it too). I'll use just Java terminology because I am more <em>au fait</em> with that.</p>\n\n<p>As the answers mentioned, <code>int</code> is just a number (called the <em>unboxed</em> type), whereas <code>Integer</code> is an object (which contains the number, hence a <em>boxed</em> type). In Java terms, that means (apart from not being able to call methods on <code>int</code>), you cannot store <code>int</code> or other non-object types in collections (<code>List</code>, <code>Map</code>, etc.). In order to store them, you must first box them up in its corresponding boxed type.</p>\n\n<p>Java 5 onwards have something called <em>auto-boxing</em> and <em>auto-unboxing</em> which allow the boxing/unboxing to be done behind the scenes. Compare and contrast: Java 5 version:</p>\n\n<pre><code>Deque&lt;Integer&gt; queue;\n\nvoid add(int n) {\n    queue.add(n);\n}\n\nint remove() {\n    return queue.remove();\n}\n</code></pre>\n\n<p>Java 1.4 or earlier (no generics either):</p>\n\n<pre><code>Deque queue;\n\nvoid add(int n) {\n    queue.add(Integer.valueOf(n));\n}\n\nint remove() {\n    return ((Integer) queue.remove()).intValue();\n}\n</code></pre>\n\n<p>It must be noted that despite the brevity in the Java 5 version, both versions generate identical bytecode. Thus, although auto-boxing and auto-unboxing are very convenient because you write less code, these operations <em>do</em> happens behind the scenes, with the same runtime costs, so you still have to be aware of their existence.</p>\n\n<p>Hope this helps!</p>\n"}, {'answer_id': 1266, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 5, 'selected': False, 'text': "<p>I'll just post here since some of the other posts are slightly inaccurate in relation to C#.</p>\n\n<p><strong>Correct:</strong> <code>int</code> is an alias for <code>System.Int32</code>.<br/>\n<strong>Wrong:</strong> <code>float</code> is not an alias for <code>System.Float</code>, but for <code>System.Single</code></p>\n\n<p>Basically, int is a reserved keyword in the C# programming language, and is an alias for the <code>System.Int32</code> value type.</p>\n\n<p>float and Float is not the same however, as the right system type for ''<code>float</code>'' is System.Single. There are some types like this that has reserved keywords that doesn't seem to match the type names directly.</p>\n\n<p>In C# there is no difference between ''<code>int</code>'' and ''<code>System.Int32</code>'', or any of the other pairs or keywords/system types, except for when defining enums. With enums you can specify the storage size to use and in this case you can only use the reserved keyword, and not the system runtime type name.</p>\n\n<p>Wether the value in the int will be stored on the stack, in memory, or as a referenced heap object depends on the context and how you use it.</p>\n\n<p>This declaration in a method:</p>\n\n<pre><code>int i;\n</code></pre>\n\n<p>defines a variable <code>i</code> of type <code>System.Int32</code>, living in a register or on the stack, depending on optimizations. The same declaration in a type (struct or class) defines a member field. The same declaration in a method argument list defines a parameter, with the same storage options as for a local variable. (note that this paragraph is not valid if you start pulling iterator methods into the mix, these are different beasts altogether)</p>\n\n<p>To get a heap object, you can use boxing:</p>\n\n<pre><code>object o = i;\n</code></pre>\n\n<p>this will create a boxed copy of the contents of <code>i</code> on the heap. In IL you can access methods on the heap object directly, but in C# you need to cast it back to an int, which will create another copy. Thus, the object on the heap cannot easily be changed in C# without creating a new boxed copy of a new int value. (Ugh, this paragraph doesn't read all that easily.)</p>\n"}, {'answer_id': 1582, 'author': 'Wedge', 'author_id': 332, 'author_profile': 'https://Stackoverflow.com/users/332', 'pm_score': 3, 'selected': False, 'text': '<p>This has already been answered for Java, here\'s the C# answer:</p>\n\n<p>"Integer" is not a valid type name in C# and "int" is just an alias for System.Int32. Also, unlike in Java (or C++) there aren\'t any special primitive types in C#, every instance of a type in C# (including int) is an object. Here\'s some demonstrative code:</p>\n\n<pre><code>void DoStuff()\n{\n    System.Console.WriteLine( SomeMethod((int)5) );\n    System.Console.WriteLine( GetTypeName&lt;int&gt;() );\n}\n\nstring SomeMethod(object someParameter)\n{\n    return string.Format("Some text {0}", someParameter.ToString());\n}\n\nstring GetTypeName&lt;T&gt;()\n{\n    return (typeof (T)).FullName;\n}\n</code></pre>\n'}, {'answer_id': 2823, 'author': 'andynil', 'author_id': 446, 'author_profile': 'https://Stackoverflow.com/users/446', 'pm_score': 4, 'selected': False, 'text': '<p>Regarding Java 1.5 and <a href="http://en.wikipedia.org/wiki/Autoboxing#Autoboxing" rel="noreferrer">autoboxing</a> there is an important "quirk" that comes to play when comparing Integer objects.</p>\n\n<p>In Java, Integer objects with the values -128 to 127 are immutable (that is, for one particular integer value, say 23, all Integer objects instantiated through your program with the value 23 points to the <em>exact</em> same object).</p>\n\n<p>Example, this returns true:</p>\n\n<pre><code>Integer i1 = new Integer(127);\nInteger i2 = new Integer(127);\nSystem.out.println(i1 == i2); //  true\n</code></pre>\n\n<p>While this returns false:</p>\n\n<pre><code>Integer i1 = new Integer(128);\nInteger i2 = new Integer(128);\nSystem.out.println(i1 == i2); //  false\n</code></pre>\n\n<p>The == compares by reference (does the variables point to the same object).</p>\n\n<p>This result may or may not differ depending on what JVM you are using. The specification autoboxing for Java 1.5 requires that integers (-128 to 127) always box to the same wrapper object. </p>\n\n<p>A solution? =) One should always use the Integer.equals() method when comparing Integer objects.</p>\n\n<pre><code>System.out.println(i1.equals(i2)); //  true\n</code></pre>\n\n<p>More info at <a href="http://today.java.net/pub/a/today/2005/03/24/autoboxing.html" rel="noreferrer">java.net</a> Example at <a href="http://bexhuff.com/2006/11/java-1-5-autoboxing-wackyness" rel="noreferrer">bexhuff.com</a></p>\n'}, {'answer_id': 3285, 'author': 'grom', 'author_id': 486, 'author_profile': 'https://Stackoverflow.com/users/486', 'pm_score': 4, 'selected': False, 'text': '<p>In Java there are two basic types in the <a href="http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#22930" rel="noreferrer">JVM</a>. 1) Primitive types and 2) Reference Types. int is a primitive type and Integer is a class type (which is kind of reference type).</p>\n\n<p>Primitive values do not share state with other primitive values. A variable whose type is a primitive type always holds a primitive value of that type.</p>\n\n<pre><code>int aNumber = 4;\nint anotherNum = aNumber;\naNumber += 6;\nSystem.out.println(anotherNum); // Prints 4\n</code></pre>\n\n<p>An object is a dynamically created class instance or an array. The reference values (often just references) are pointers to these objects and a special null reference, which refers to no object. There may be many references to the same object.</p>\n\n<pre><code>Integer aNumber = Integer.valueOf(4);\nInteger anotherNumber = aNumber; // anotherNumber references the \n                                 // same object as aNumber\n</code></pre>\n\n<p>Also in Java everything is passed by value. With objects the value that is passed is the reference to the object. So another difference between int and Integer in java is how they are passed in method calls. For example in</p>\n\n<pre><code>public int add(int a, int b) {\n    return a + b;\n}\nfinal int two = 2;\nint sum = add(1, two);\n</code></pre>\n\n<p>The variable <em>two</em> is passed as the primitive integer type 2. Whereas in</p>\n\n<pre><code>public int add(Integer a, Integer b) {\n    return a.intValue() + b.intValue();\n}\nfinal Integer two = Integer.valueOf(2);\nint sum = add(Integer.valueOf(1), two);\n</code></pre>\n\n<p>The variable <em>two</em> is passed as a reference to an object that holds the integer value 2.</p>\n\n<hr>\n\n<p>@WolfmanDragon:\nPass by reference would work like so:</p>\n\n<pre><code>public void increment(int x) {\n  x = x + 1;\n}\nint a = 1;\nincrement(a);\n// a is now 2\n</code></pre>\n\n<p>When increment is called it passes a reference (pointer) to variable <em>a</em>. And the <em>increment</em> function directly modifies variable <em>a</em>.</p>\n\n<p>And for object types it would work as follows:</p>\n\n<pre><code>public void increment(Integer x) {\n  x = Integer.valueOf(x.intValue() + 1);\n}\nInteger a = Integer.valueOf(1);\nincrement(a);\n// a is now 2\n</code></pre>\n\n<p>Do you see the difference now?</p>\n'}, {'answer_id': 3464, 'author': 'Telcontar', 'author_id': 518, 'author_profile': 'https://Stackoverflow.com/users/518', 'pm_score': 3, 'selected': False, 'text': "<p>One more thing that I don't see in previous answers:\nIn Java the primitive wrappers classes like Integer, Double, Float, Boolean... and String are suposed to be invariant, so that when you pass an instance of those classes the invoked method couldn't alter your data in any way, in opositión with most of other classes, which internal data could be altered by its public methods. So that this classes only has 'getter' methods, no 'setters', besides the constructor.</p>\n\n<p>In a java program String literals are stored in a separate portion of heap memory, only a instance for literal, to save memory reusing those instances</p>\n"}, {'answer_id': 498102, 'author': 'mP.', 'author_id': 56524, 'author_profile': 'https://Stackoverflow.com/users/56524', 'pm_score': 3, 'selected': False, 'text': '<p>In platforms like Java, <code>int</code>s are primitives while <code>Integer</code> is an object which holds a integer field. The important distinction is that primitives are always passed around by value and by definition are immutable. </p>\n\n<p>Any operation involving a primitive variable always returns a new value. On the other hand, objects are passed around by reference. One could argue that the point to the object (AKA the reference) is also being passed around by value, but the contents are not.</p>\n'}, {'answer_id': 8462531, 'author': 'nagarajn89', 'author_id': 1055140, 'author_profile': 'https://Stackoverflow.com/users/1055140', 'pm_score': 3, 'selected': False, 'text': '<p>int is used to declare primitive variable </p>\n\n<pre><code>e.g. int i=10;\n</code></pre>\n\n<p>Integer is used to create reference variable of class Integer</p>\n\n<pre><code>Integer a = new Integer();\n</code></pre>\n'}, {'answer_id': 23711054, 'author': 'Mr.Q', 'author_id': 3593084, 'author_profile': 'https://Stackoverflow.com/users/3593084', 'pm_score': 3, 'selected': False, 'text': '<p>have you ever programmed before then (int) is one of the primitive types you can set for your variables (just like char, float, ...).</p>\n\n<p>but Integer is a wrapper class that you can use it to do some functions on an int variable (e.g convert it to string or vise versa,...) , but keep note that methods in the wrapper classes are static so you can use them anytime without creating an instance of Integer class.\nas a recap :</p>\n\n<pre><code>int x;\nInteger y; \n</code></pre>\n\n<p>x and y are both variables of type int but y is wrapped by an Integer class and has several methods that you use,but i case you need to call some functions of Integer wrapper class you can do it simply.</p>\n\n<pre><code>Integer.toString(x);\n</code></pre>\n\n<p>but be aware that both x and y are corect but if you want to use them just as a primitive type, use the simple form (used for defining x).</p>\n'}, {'answer_id': 24795920, 'author': 'Bindumalini KK', 'author_id': 3790709, 'author_profile': 'https://Stackoverflow.com/users/3790709', 'pm_score': 2, 'selected': False, 'text': "<p>In both languages (Java and C#) <code>int</code> is 4-byte signed integer.</p>\n\n<p>Unlike Java, C# Provides both signed and unsigned integer values. As Java and C# are object object-oriented, some operations in these languages do not map directly onto instructions provided by the run time and so needs to be defined as part of an object of some type.</p>\n\n<p>C# provides <code>System.Int32</code> which is a value type using a part of  memory that belongs to the reference type on the heap.</p>\n\n<p>java provides <code>java.lang.Integer</code> which is a reference type operating on <code>int</code>. The methods in <code>Integer</code> can't be compiled directly to run time instructions.So we box an int value to convert it into an instance of Integer and use the methods which expects instance of some type (like <code>toString()</code>, <code>parseInt()</code>, <code>valueOf()</code> etc).</p>\n\n<p>In C# variable  int refers to <code>System.Int32.Any</code> 4-byte value in memory can be interpreted as a primitive int, that can be manipulated by  instance of System.Int32.So int is an alias for <code>System.Int32.When</code> using integer-related methods like <code>int.Parse()</code>, <code>int.ToString()</code> etc. Integer is compiled into the FCL <code>System.Int32</code> struct calling the respective methods like <code>Int32.Parse()</code>, <code>Int32.ToString()</code>.</p>\n"}, {'answer_id': 25056184, 'author': 'Shravan', 'author_id': 3895136, 'author_profile': 'https://Stackoverflow.com/users/3895136', 'pm_score': 3, 'selected': False, 'text': '<p>There are many reasons to use wrapper classes:</p>\n\n<ol>\n<li>We get extra behavior (for instance we can use methods)</li>\n<li>We can store null values whereas in primitives we cannot</li>\n<li>Collections support storing objects and not primitives.</li>\n</ol>\n'}, {'answer_id': 25180570, 'author': 'Rufaro Muchedzi', 'author_id': 3917868, 'author_profile': 'https://Stackoverflow.com/users/3917868', 'pm_score': 2, 'selected': False, 'text': '<p>An int and Integer in Java and C# are two different terms used to represent different things. It is one of the the primitive data types that can be assigned to a variable that can store exactly. One value of its declared type at a time.</p>\n\n<p><strong>For example:</strong></p>\n\n<pre><code>int number = 7;\n</code></pre>\n\n<p>Where <code>int</code> is the datatype assigned to the variable number which holds the value seven. So an <code>int</code> is just a primitive not an object.</p>\n\n<p>While an <code>Integer</code> is a wrapper class for a primitive data type which has static methods. That can be used as an argument to a method which requires an object, where as int can be used as an argument to a method which requires an integer value, that can be used for arithmetic expression. </p>\n\n<p><strong>For example:</strong></p>\n\n<pre><code>Integer number = new Integer(5);\n</code></pre>\n'}, {'answer_id': 33936777, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>An int variable holds a 32 bit signed integer value. An Integer (with capital I) holds a reference to an object of (class) type Integer, or to null.</p>\n\n<p>Java automatically casts between the two; from Integer to int whenever the Integer object occurs as an argument to an int operator or is assigned to an int variable, or an int value is assigned to an Integer variable. This casting is called boxing/unboxing.</p>\n\n<p>If an Integer variable referencing null is unboxed, explicitly or implicitly, a NullPointerException is thrown.</p>\n'}, {'answer_id': 35686676, 'author': 'Aqeel Haider', 'author_id': 4165553, 'author_profile': 'https://Stackoverflow.com/users/4165553', 'pm_score': 2, 'selected': False, 'text': '<p>In Java int is a primitive data type while Integer is a Helper class, it is use to convert for one data type to other. </p>\n\n<p>For example: </p>\n\n<pre><code>double doubleValue = 156.5d;\nDouble doubleObject  = new Double(doubleValue);\nByte myByteValue = doubleObject.byteValue ();\nString myStringValue = doubleObject.toString();\n</code></pre>\n\n<p>Primitive data types are store the fastest available memory where the Helper class is complex and store in heep memory. </p>\n\n<p>reference from "David Gassner" Java Essential Training. </p>\n'}, {'answer_id': 37797743, 'author': 'J-Alex', 'author_id': 5898696, 'author_profile': 'https://Stackoverflow.com/users/5898696', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Java:</strong> </p>\n\n<p><code>int</code>, <code>double</code>, <code>long</code>, <code>byte</code>, <code>float</code>, <code>double</code>, <code>short</code>, <code>boolean</code>, <code>char</code> - primitives. Used for hold the basic data types\nsupported by the language. the primitive types are not part of the\nobject hierarchy, and they do not inherit Object. Thet can\'be pass by reference to a method. </p>\n\n<p><code>Double</code>, <code>Float</code>, <code>Long</code>, <code>Integer</code>, <code>Short</code>, <code>Byte</code>, <code>Character</code>, and <code>Boolean</code>, are type Wrappers, packaged in <code>java.lang</code>. All of the numeric type wrappers define constructors that allow an object to be constructed from a given value, or a string representation of that value.\nUsing objects can add an overhead to even the simplest of calculations. </p>\n\n<p>Beginning with JDK 5, Java has included two very helpful features: autoboxing and autounboxing. Autoboxing/unboxing greatly simplifies and streamlines code that must convert primitive types into objects, and vice versa.  </p>\n\n<p>Example of constructors:</p>\n\n<pre><code>Integer(int num)\nInteger(String str) throws NumberFormatException\nDouble(double num)\nDouble(String str) throws NumberFormatException\n</code></pre>\n\n<p>Example of boxing/unboxing:</p>\n\n<pre><code>class ManualBoxing {\n        public static void main(String args[]) {\n        Integer objInt = new Integer(20);  // Manually box the value 20.\n        int i = objInt.intValue();  // Manually unbox the value 20\n        System.out.println(i + " " + iOb); // displays 20 20\n    }\n}\n</code></pre>\n\n<p>Example of autoboxing/autounboxing:</p>\n\n<pre><code>class AutoBoxing {\n    public static void main(String args[]) {\n        Integer objInt = 40; // autobox an int\n        int i = objInt ; // auto-unbox\n        System.out.println(i + " " + iOb); // displays 40 40\n    }\n}\n</code></pre>\n\n<p>P.S. Herbert Schildt\'s book was taken as a reference.</p>\n'}, {'answer_id': 39635844, 'author': 'Aatu Dave', 'author_id': 6863552, 'author_profile': 'https://Stackoverflow.com/users/6863552', 'pm_score': 0, 'selected': False, 'text': '<p>In java as per my knowledge if you learner then, when you write int a; then in java generic it will compile code like <code>Integer a = new Integer()</code>.\nSo,as per generics <code>Integer</code> is not used but <code>int</code> is used.\nso there is so such difference there.</p>\n'}, {'answer_id': 42617947, 'author': 'Mausam Sinha', 'author_id': 6201874, 'author_profile': 'https://Stackoverflow.com/users/6201874', 'pm_score': 1, 'selected': False, 'text': '<p><code>int</code> is predefined in library function c# but in java we can create object of <code>Integer</code> </p>\n'}, {'answer_id': 43651213, 'author': 'thamashi97', 'author_id': 7859659, 'author_profile': 'https://Stackoverflow.com/users/7859659', 'pm_score': 2, 'selected': False, 'text': '<p>In Java, the <code>int</code> type is a primitive data type, where as the <code>Integer</code> type is an object.</p>\n\n<p>In C#, the <code>int</code> type is also a data type same as <code>System.Int32</code>. An <code>integer</code> (just like any other value types) can be boxed ("wrapped") into an object.</p>\n'}, {'answer_id': 45503764, 'author': 'MD RAHIIM', 'author_id': 7825278, 'author_profile': 'https://Stackoverflow.com/users/7825278', 'pm_score': 2, 'selected': False, 'text': '<p>"int" is primitive data-type and "Integer" in Wrapper Class in Java. "Integer" can be used as an argument to a method which requires an object, where as "int" can be used as an argument to a method which requires an integer value, that can be used for arithmetic expression.</p>\n'}, {'answer_id': 48816251, 'author': 'Rishabh Agarwal', 'author_id': 3878948, 'author_profile': 'https://Stackoverflow.com/users/3878948', 'pm_score': 0, 'selected': False, 'text': '<p>(Java Version)\nIn Simple words <code>int</code> is primitive (cannot have null value) and Integer is wrapper object for int.</p>\n<p>One example where to use Integer vs int, When you want to compare and int variable again null it will throw error.</p>\n<pre><code>int a;\n//assuming a value you are getting from data base which is null\nif(a ==null) // this is wrong - cannot compare primitive to null\n{\ndo something...}\n\nInstead you will use,\nInteger a;\n//assuming a value you are getting from data base which is null\nif(a ==null) // this is correct/legal\n{ do something...}\n</code></pre>\n'}, {'answer_id': 50699096, 'author': 'Priyantha', 'author_id': 7467246, 'author_profile': 'https://Stackoverflow.com/users/7467246', 'pm_score': 1, 'selected': False, 'text': '<p><strong>01. Integer can be null. But int cannot be null.</strong></p>\n\n<pre><code>Integer value1 = null; //OK\n\nint value2 = null      //Error\n</code></pre>\n\n<p><strong>02. Only can pass Wrapper Classes type values to any collection class.</strong></p>\n\n<p>(Wrapper Classes - Boolean,Character,Byte,Short,Integer,Long,Float,Double)</p>\n\n<pre><code>List&lt;Integer&gt; element = new ArrayList&lt;&gt;();\nint valueInt = 10;\nInteger  valueInteger = new Integer(value);\nelement.add(valueInteger);\n</code></pre>\n\n<p>But normally we add primitive values to collection class? Is point 02 correct?</p>\n\n<pre><code>List&lt;Integer&gt; element = new ArrayList&lt;&gt;();\nelement.add(5);\n</code></pre>\n\n<p>Yes 02 is correct, beacouse <code>autoboxing.</code></p>\n\n<blockquote>\n  <p>Autoboxing is the automatic conversion that the java compiler makes\n  between the primitive type and their corresponding wrapper class.</p>\n</blockquote>\n\n<p>Then 5 convert as Integer value by autoboxing. </p>\n'}, {'answer_id': 56422463, 'author': 'Kavinda Pushpitha', 'author_id': 9036713, 'author_profile': 'https://Stackoverflow.com/users/9036713', 'pm_score': 0, 'selected': False, 'text': '<p><strong>int</strong> is a primitive data type.\n<strong>Integer</strong> is a wrapper class. It can store int data as objects.</p>\n'}, {'answer_id': 56863511, 'author': 'Lourdes', 'author_id': 11732298, 'author_profile': 'https://Stackoverflow.com/users/11732298', 'pm_score': 0, 'selected': False, 'text': "<p>int is a primitive datatype whereas Integer is an object. \nCreating an object with Integer will give you access to all the methods that are available in the Integer class. \nBut, if you create a primitive data type with int, you will not be able to use those inbuild methods and you have to define them by yourself.\nBut, if you don't want any other methods and want to make the program more memory efficient, you can go with primitive datatype because creating an object will increase the memory consumption.</p>\n"}]
['https://Stackoverflow.com/questions/564', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/25/']