written 7.9 years ago by | • modified 7.9 years ago |
Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology
Marks: 5 M
Year: Dec 2013, Dec 2014, May 2015
written 7.9 years ago by | • modified 7.9 years ago |
Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology
Marks: 5 M
Year: Dec 2013, Dec 2014, May 2015
written 7.9 years ago by |
Simple Type | Wrapper Class |
---|---|
Boolean | Boolean |
Char | Character |
Double | Double |
Float | Float |
Int | Integer |
Long | Long |
There are mainly two applications of wrapper classes.
1) To convert simple data types into objects, that is, to give object form to a data type; here constructors are used.
2) To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.
For example,
int k = 100;
Integer it1 = new Integer(k);
The int data type k is converted into an object, it1 using Integer class. The it1 object can be used in Java programming wherever k is required an object.
The following code can be used to unwrap (getting back int from Integer object) the object it1.
int m = it1.intValue();
System.out.println(m*m); // prints 10000
Conversion of Strings to Primitive data types can be carried out as follows:
int i= Integer.parseInt(Str); //converts string to primitive integer
long i= Long.parseLong(Str); //converts string to primitive long