Wrapper Class - Converting string object to primitive numbers in Java


A Wrapper class is a class whose object wraps or contains primitive data types. When we create an object to a wrapper class, it contains a field and in this field, we can store primitive data types. In other words, we can wrap a primitive value into a wrapper class object.

Source Code

public class wrapperClass4 {
    public static void main(String args[])
    {
        //Converting string object to primitive numbers.
        String SI="25";
        Integer I= Integer.valueOf(SI);
        int i= I.intValue();
        System.out.println(i);
        String SD="25.25";
        Double D= Double.valueOf(SD);
        double d= D.doubleValue();
        System.out.println(d);
    }
}
 

Output

25
25.25
To download raw file Click Here

Basic Programs