• Java Wrapper Classes

    Java Wrapper Classes

    In Java Wrapper Classes, The vectors cannot handle primitive data types like int, float, long, char,  and double. Primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package. Below table shows the simple data types and their corresponding wrapper class types.

    Simple Type

    Wrapper Class

    boolean

    Boolean

    char

    Character

    double

    Double

    float

    Float

    int

    Integer

    long

    Long

     

    Converting Primitive to Objects Using Constructor Converting Objects to Primitive using method Converting Numbers to Strings Converting String objects to Numeric objects Converting Numeric Strings to Primitive Numbers
    Integer IntVal = new Integer() int i =  IntVal.intValue() str = Integer.toString(i) IntVal = Integer.valueOf() int i = Integer.parseInt(str)
    Float FloatVal = new Float() float f = FloatVal.floatValue() str = Float.toString(f) FloatVal = Float.valueOf() long l = Long.parseLong(str)
    Double DoubleVal = new Double() double d =  DoubleVal.doubleValue() str = Double.toString(d) DoubleVal = Double.valueOf()
    Long LongVal = new Long() long l = LongVal.longValue() str = Long.toString(l) LongVal = Long.valueOf()

    The Wrapper classes have number of methods for handling primitive data types and objects.

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *