Possible duplicate:Why can Integer and int be used interchangeably?
I am trying to understand the difference between the two. Can I declare something as an int, and then compare this with the number I entered in Integer? Also why Java has two. Why not just combine them?
Can someone help me by showing me an example with line code 3-4, how each one is used?
intprimitive is not an object. Arrays allow primitives:
int
int[] array = new int[10];
but there are no generics:
List<int> //won't compile
- . Integer, Object. , Integer null, .
Integer
Object
null
, , . # , scala int AnyVal, extend AnyRef ( Any).
AnyVal
AnyRef
Any
. boxing Java. , , Java 9.
intValue
- , int - . , , . , .
Java . - :
Integer.toString()
, :
int.toString()
.
int , Integer - . ArrayList<int>, ArrayList<Integer>.
ArrayList<int>
ArrayList<Integer>
All primitive types in Java have their own class analogues (classes derived from Object), such as Boolean, Long, etc. This is called boxing. For an explanation see, for example, here .