Four methods of Wrapper classes:
1) valueOf()
2) xxxValue()
3) parseXxx()
4) toString()
valueOf():
Every wrapper class except Character class contains a static valueOf() method to create Wrapper class object for given String. Integer i=Integer.valueOf(“10”);
xxxValue()
xxxValue() methods are used to get the primitive for the given Wrapper Object. Every number type
Wrapper class( Byte, Short, Integer, Long, Float, Double) contains the following 6 methods to get
primitive for the given Wrapper object:
syntax :
public static datatype parseXxx(String s);
1. public byte byteValue()
2. public short shortValue()
3. public int intValue()
4. public long longValue()
5. public float floatValue()
6. public float doubleValue()
parseXxx()
parseXxx() methods can be used to convert String to primitive. Xxx contains data type as follows:
parseInt(String str) parseFloat(String str)
parseLong(Strung str)
parseDouble(String str)
toString()
Every Wrapper class contains the following
toString() method to convert primitive to String.
Syntax:
public String toString();
for eg: Integer.toString(5);
0 Comments