please tell me what is wrapper class in java with example ?

Answer Posted / vikneswarank

its a class used to convert primitive data type to user
defined data type like Integer

for example

public class WrapperSample1
{
public static void main (String args[])
{
int iVal = 100;
long lVal = 200;
float fVal = 300;
double dVal = 400;

String str = "123";

//primitive types to corresponding wrapper objects
Integer intVal = Integer.valueOf(iVal);
Long lgVal = Long.valueOf(lVal);
Double dbVal = Double.valueOf(dVal);
Float ftVal = Float.valueOf(fVal);

//primitive types to string objects
str = String.valueOf(iVal);
str = String.valueOf(lVal);
str = String.valueOf(fVal);
str = String.valueOf(dVal);

//wrapper Objects to corresponding primitive types
iVal = intVal.intValue();
lVal = lgVal.longValue();
fVal = ftVal.floatValue();
dVal = dbVal.doubleValue();

//String to primitive types
iVal = Integer.parseInt(str);
lVal = Long.parseLong(str);
fVal = Float.parseFloat(str);
dVal = Double.parseDouble(str);

//string to wrapper objects
intVal = Integer.valueOf(str);
lgVal = Long.valueOf(str);
ftVal = Float.valueOf(str);
dbVal = Double.valueOf(str);
}
}

Is This Answer Correct ?    60 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a class reference?

784


Can we force the garbage collection to run?

732


What is r * in math?

750


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

838


How define set in java?

787


Can we return null in java?

849


What do you mean by hashing?

865


Explain the private field modifier?

852


What is bigger kb or mb?

803


Can a string be null?

755


How to perform merge sort in java?

816


Which category the java thread do fall in?

772


Is 0 true or false in java?

770


Can you explain the meaning of aggregation and composition

778


What are the Main functions of Java?

860