The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Creating Wrapper Objects

The most straightforward way to create a wrapper object is to use its constructor:

    Integer i = new Integer (17);
    Double d = new Double (3.14159);
    Character c = new Character ('b');

Technically String is not a wrapper class, because there is no corresponding primitive type, but the syntax for creating a String object is the same:

    String s = new String ("fred");

On the other hand, no one ever uses the constructor for String objects, because you can get the same effect with a simple String value:

    String s = "fred";


Last Update: 2011-01-24