Wrapper Class in Java

Wrapper Class in Java


Wrapper Class In Java Notes

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:

  1. Boolean
  2. Byte
  3. Integer
  4. Float
  5. Character
  6. Short
  7. Long
  8. 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);