http://stackoverflow.com/questions/3579035/why-are-there-wrapper-classes-in-java
- So that a null value is possible
- To include in a Collection
- To treat generically / polymorphically as an Object along with other Objects
- Always use
Double
overFloat
Integer
Wrapper Class is autoboxed when compared until from-128
to (and with)127
Integer j1 = 2;
Integer j2 = 2;
System.out.println( j1 == j2 ); // true
Integer k1 = 127;
Integer k2 = 127;
System.out.println( k1 == k2 ); // true
Integer l1 = 128;
Integer l2 = 128;
System.out.println( l1 == l2 ); // false
Integer m1 = 1000;
Integer m2 = 1000;
System.out.println( m1 == m2 ); // false
- convert primitive type to wrapper class, use
WrapperClass.valueOf()
// implicit conversion
Integer x = 100;
// explicit conversion
Integer x = Integer.valueOf(100);
- Convert wrapper class to primitive type
Integer x = Integer.valueOf(10);
// implicit conversion
int y = x;
// explicit conversion
int y = x.intValue();
Integer.parseInt(String)
returns a primitiveint
Integer.valueOf(String)
return aInteger
wrapper class