Wrapper classes in Java

There are Eight primitive or basic data types in Java. Each of this primitive data type has corresponding Wrapper class. It is possible to convert primitive type to Wrapper class, and vice versa.

Basic Data Type Wrapper Type
int java.lang.Integer
float java.lang.Float
short java.lang.Short
byte java.lang.Byte
long java.lang.Long
double java.lang.Double
char java.lang.Character
boolean java.lang.Boolean

How to convert String to float?

public class HelloWolrd {

	public static void main(String[] args)
		String str ="23.14f";

		float val = Float.parseFloat(str);

		System.out.println("Converted float value is:"+val);
		catch(NumberFormatException nfe)

You may also like to read:
Autoboxing and Autounboxing
what is assertion in Java?
What are built in exceptions in Java

One thought on “Wrapper classes in Java”

Leave a Reply