Wrapper Class in Java
Wrapper Class in Java
These are part of Java’s standard library java.lang and these convert primitive data types in an object. In other words, a wrapper class wraps a value of primitive type in an object.
Java provides the following wrapper classes:
- Boolean
- Byte
- Integer
- Float
- Character
- Short
- Long
- Double
Here are some examples to understand how to use them.
Conversion from string to a primitive type can be done in the following way:
String s1=â€15â€;
int n = Integer.parseInt(s1);
String s2 = â€-4.6â€;
float f = Float.parseFloat(s2);
Conversion from primitive types to String can be done as follows:
int n=15;
String s1=Integer.toString(n);