Hi
I want to know what is the benifit of the Wrapper classes in java.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Feb 7, 2012, 12:24 AM
Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character, Double etc.
Dealing with primitives as objects is easier at times. Most of the objects collection store objects and not primitive types. Many utility methods are provided by wrapper classes. To get these advantages we need to use wrapper classes. As they are objects, they can be stored in any of the collection and pass this collection as parameters to the methods.
Features of the Java wrapper Classes.
Wrapper classes convert numeric strings into numeric values.
The way to store primitive data in an object.
The valueOf() method is available in all wrapper classes except Character
All wrapper classes have typeValue() method. This method returns the value of the object as its primitive type.
Java uses primitive types and are part of any object hierarchy. These values are passed to methods by values.
Character class methods:
isDigit() – to determine whether the character is digit.
isLower() – to determine whether the character is lower case alphabet.
is Letter() – to determine whether the character is an alphabet.
Ex:
if(Character.isDigit(a[i]))
System.out.println(a[i] + "is a digit ");
if(Character.isLetter(a[i]))
System.out.println(a[i] + "is a letter ");
Byte class methods:
byteValue() – returns the Byte value as byte value
Ex : byte bvalue = Byte.byteValue();
parseByte() – returns byte value from a byte string
Ex: byte bvaue = Byte.parseByte("93");
Integer class methods:
intValue() – returns the Integer value as int value
Ex: int bvalue = Integer.intValue();
parseInt() – returns int value from a int string
Ex: int bvaue = Integer.parseInt("73");
Thanks