Converting Wrapped primitives to primitives

Edit on Github instead

While objects can be useful, sometimes we prefer to work with primitives. Here's how we go from a Wrapper class to a primitive:

Integer i = new Integer(4);
int j = i.intValue();
// j now has the value 4

Double d = new Double(5.2);
double e = d.doubleValue();
// e now has the value 5.2

Boolean b = new Boolean(true);
boolean c = b.booleanValue();
// c now has the value true

Java 5.0+ automatically converts between primitives and wrapped objects by autoboxing.

Suggest changes

Related links

URL Topic Source