O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wrapper Classes

You can't call a method on a Java primitive, such as an int or a double. And sometimes that's a problem because you would like to be able to. Sometimes, you need to hold a list of these kinds of values, and you want to use the classes in the Java Collections Framework; the problem here is that none of those data structures, such as ArrayList, Hashtable, or Vector, will hold primitive types. They only hold objects.

So what's a girl to do? Use the wrapper classes that come with the Java API. There is a class in the java.lang package that corresponds to each of the primitive types. Table 11-1 shows these classes.

11-1. The Primitive Wrapper Classes
WRAPPERPRIMITIVE
Booleanboolean
Bytebyte
Shortshort
Characterchar
Integerint
Longlong
Float ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required