Wrapper Class in Java With Example | Full Stack With Java

Wrapper Class in Java : – Convert String into Primitive Data Type

Primitive Data TypeWrapper Class
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
booleanBoolean
charCharacter

Example 1 : String to Integer

public class A   {
public static void main(String[] args) {
	String x ="100";
	int i = Integer.parseInt(x);
	System.out.println(i);
}
}
Output : 100

Example 2 : String to Double

public class A   {
public static void main(String[] args) {
	String z ="10.3";
	double d = Double.parseDouble(z);
	System.out.println(d);
}
}

You Also Learn –

Wrapper Class in Java

Output : 10.3

Example 3 : String to Boolean

public class A   {
public static void main(String[] args) {
	String k = "true";
	boolean b = Boolean.parseBoolean(k);
	System.out.println(b);
}
}
Output : true

Example 4 : String to Float

public class A {
public static void main(String[] args) {
String o= “20.34”;
float f = Float.parseFloat(o);
System.out.println(f);
}
}

Output :  20.34

Leave a Comment