Primitive Wrappers in detail : Wrapper Classes « Data Type « Java Tutorial






For the sake of performance, not everything in Java is an object. There are also primitives, such as int, long, float, double, etc.

java.lang.Integer

  1. The java.lang.Integer class wraps an int.
  2. The Integer class has two static final fields of type int: MIN_VALUE and MAX_VALUE.
  3. MIN_VALUE contains the minimum possible value for an int (-2^31) and
  4. MAX_VALUE the maximum possible value for an int (2^31 - 1).

Integer class has two constructors:

public Integer (int value)
     public Integer (String value)

For example, this code constructs two Integer objects.

Integer i1 = new Integer (12);
     Integer i2 = new Integer ("123");

Integer has the no-arg byteValue, doubleValue, floatValue, intValue, longValue, and shortValue methods that convert the wrapped value to a byte, double, float, int, long, and short, respectively. In addition, the toString method converts the value to a String.

static methods parse a String to an int (parseInt) and convert an int to a String (toString).

public static int parsetInt (String string)
     public static String toString (int i)








2.17.Wrapper Classes
2.17.1.Wrapper classes for the primitive types
2.17.2.Primitive Wrappers in detail
2.17.3.Demonstrate a type wrapper.
2.17.4.Autoboxing/unboxing int
2.17.5.Use Integer constructor to convert int primitive type to Integer object.
2.17.6.Wrapped Class: boolean, int, long