Hello,
Please post a suitable example of wrapped class in java.
Thanks in advance!
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.
Amit ChoudharyPosted Aug 1, 2011, 4:21 PM
import java.util.*;
public class VecNum
{
public static void main(String argv[])
{
Vector v = new Vector();
v.add(new Integer(1));
v.add(new Integer(2));
for(int i=0; i < v.size();i ++)
{
Integer iw =(Integer) v.get(i);
System.out.println(iw.intValue());
}
}
}
The wrapper classes also offer utility methods for converting to and from the int values they represent. Thus if you have a string that could also represent a number, you can use a wrapper class to perform that calculation
The methods of the wrapper classes are all static so you can use them without creating an instance of the matching wrapper class. Note that once a wrapper has a value assigned to it that value cannot be changed.
See more details here.
Sam HobbsPosted Aug 1, 2011, 6:48 PM
Is that the entire question? Did Amit answer the question? If he did then please check the checkbox indicating it is an answer. I hope you get an A+ for Amit's answer.