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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit ChoudharyRank #145 · 15.8K reputationPosted Aug 1, 2011, 12:21 PM EDT
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 HobbsRank #107 · 20.5K reputationPosted Aug 1, 2011, 2:48 PM EDT
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.