1 / 1100%
Wrapper Classes
A wrapper class represents a particular primitive data type.
(primitive data types int, double, char, boolean, and so on)
They are defined in the java.lang package.
Instead of declaring an integer as primitive data as:
int number1 = 45;
We can declare it as an object of the Integer (wrapper) class.
Integer number1 = new Integer(45);
For instance, the method doubleValue() returns the value of this integer as double.
The class Integer also has static methods such as parseInt(String str) that returns the
int corresponding to the value stored in the parameter string. Since it is static, it can be called
with the class name (without instantiating an obejct) as:
int num = Integer.parseInt(11);
Then num will contain the integer 11.
Also see other wrapper classes such as Double. (e.g., double num2 = Double.parseDouble(3.21); )
Powered by TCPDF (www.tcpdf.org)
Students also viewed