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. |
Home Stacks Creating Wrapper Objects | ||
See also: Wrapper Classes, Creating More Wrapper Objects | ||
Search the VIAS Library | Index | ||
Creating Wrapper Objects
The most straightforward way to create a wrapper object is to use its constructor: 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";
|
||
Home Stacks Creating Wrapper Objects |