Java Basic Examples

Convert String to Wrapper Object Example

This example shows how to convert String to wrapper objects like String to Integer object, String to Long object, String to Float object, String to Double object, String to Byte object and String to Short object.

How to convert String to Wrapper objects in Java?

There are a couple of methods using which String can be converted to wrapper class objects.

1) Convert String to Wrapper objects using Wrapper class constructor

Wrapper class provides constructor that accepts String as an argument and returns the wrapper object.

Output

2) Convert String to Wrapper objects using valueOf method of Wrapper class

Use valueOf static method of the respective wrapper class to convert from String to wrapper object as given below.

Please let us know your views in the comments section below.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.

Tags