Java

Topic: Wrapperclass

What are wrappers?

Rappers are performers or heavily rhymed couplets backed by a beat heavy rhythm in the popular music genre. However in Java wrappers are classes that wrap up primitive values in classes that offer utility methods to manipulate the values. If for example you want to store a set of int values in the elements of a Vector, the values in a Vector must be objects and not primitives. When you want to retrieve the values wrapped up in the Integers that are in the Vector elements you will need to cast the elements back to Integers and then call the toxxValue in order to get back the original number. The following code demonstrates this technique.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());    }   }}

Browse random answers:

What are Wrapper Classes? Describe the wrapper classes in Java.?
What are wrappers?
What are Utility methods in java?
Explain conversion toHexString?
Which of the following statements are true?
What will happen when you attempt to compile and run the following code?public class WrapMat{    public static void main(String argv[]){    Integer iw = new Integer(2);    Integer iw2 = new Integer(2);    System.out.println(iw * iw2);    System.out.println(iw.floatValue());   }}1 )Compile time error2) Compilation and output of 4 followed by 2.03) Compilation and output of 4 followed by 24) Compile time error, the Integer class has no floatValue method
What will happen when you attempt to compile nad run the following code?public class TwoEms {    public static void main(String argv[]){        Object[] oa = new Object[3];        oa[0] = new Integer(1);        int i = oa[0];        System.out.print(i);            }    }1) Compile time error an array cannot contain object references2) Compile time error elements in an array cannot be anonymous3) Compilation and output of 14) Compile time error Integer cannot be assigned to int5) Compilation and output of the memory address of the Integer instance
What will happen when you attempt to compile and run the following code?public class TwoPack {    public static void main(String argv[]){        Integer iw = new Integer(“2”);        Integer iw2 = new Integer(“2”);        String sOut = iw + iw2;        System.out.println(sOut);            }    }1) Compile time error, the + operator cannot be applied to Integer2) Compilation and output of 223) Compilation and output of 44) Compile time error, Integer has no String constructor
Which of the following is valid code?1) System.out.println(Integer.toBinaryString(4));2) System.out.println(Integer.toOctalString(4));3) System.out.println(Integer.add(2,2));4) Float[] ar = new Float[] { new Float(1.0), new Float(2.1)};
Insert an object with the add(Object) method