Tuesday, July 8, 2008

Wrapper classes for primitive types

Constructors
Integer (int i)
Integer(String s)

Methods to Convert primitive integer type to Integer Object
public static Integer decode(String s)
public static Integer valueOf(String s) => The string format can be number, leading 0 for octal, # or 0x for Hexadecimal
public static Integer valueOf(String s, int radix)

Methods to convert Integer Object to different primitive types
public byte byteValue()
public double doubleValue()
public float floatValue()
public int intValue()
public long longValue()
public short shortValue()

Methods for converting a String to primtive type
public int parseInt(String s)
public int parseInt(String s, int radix)

Methods for converting a primitive type to String
public static String toString(int i)
public static String toBinaryString(int i)
public static String toHexString(int i)
public static String toOctalString(int i)

Methods to compare Integer Object
public boolean equals(Object x)
public int compareTo(Integer x)

Integer.MIN_VALUE and Integer.MAX_VALUE fields to compare max and min values for a particular Object type.

This is similar for Short, byte, boolean, long, double, float.

1 comment:

Anish Antony said...

http://www.behindjava.com/2014/06/primitive-and-wrapper-classes-in-java.html