Write about Wrapper Classes in Java?

Wrapper classes:

1. Vectors can’t handle primitive data types like in , char , float , long , double.

2. vector handle only objects so wrapper classes are used to convert primitive data types in to object type.
           
          Simple type

            int
            char
            double
            float
            long
Wrapper type

Integer
Character
Double
Float
Long

Converting Primitive Data type in to Objects:

 Integer x= new Integer(i) --> integer to integer object

 Float f= new Float(i) --> float to float object

 Long l=new Long(i) --> long to long object.

 Ex :
int i=10;
Integer x =new Integer(i)
Where i=10 is integer and x is object.

Converting Objects to Primitive Data type:

int I =  IntVal . intValue (); object to primitive integer

float f =FloatVal . floatValue (); object to primitive float

long l= LongVal . longValue (); object to primitive long

Ex :

Integer x= new Integer(10);
int i= x. intValue();

Converting numbers to string using to string( ):

S1 = Integer . toString (i); primitive integer to string

S1 = Float . toString (f); primitive float to string

Ex :

int i=10;
S= Integer . toString(i);

Converting String Objects to Numeric Objects:

I= Integer. valueOf(s); convert string to integer objects.

F= Float. valueOf (s);  convert string to float object.

Converting Strings to primitive numbers : In this case we can use passing methods.

int i= Integer. parseInt(str); --> convert string to integer

float f= Float.parseFloat(str); -->convert string to float

long l=Long.parseLong(str); -->convert string to long


Related

Difference Between Overriding & Over Loading in Java?

Difference between overriding & over loading: Method overriding is used to provide a different implementation for the same feature of the software it is code replacement. Method over loading...

Final variables and methods in Java

final variables and methods( ): All methods and variables can be overridden by default in subclass. If we wish to parent the sub classes from overriding the members of the super class, we can decl...

Differences between String class and String Buffer class?

Differences between string class and string buffer class: String objects are immutable and string buffer objects are mutable. Methods to manipulate the data are not available in string class. th...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item