Language syntax

Boxing and unboxing conversions

Boxing converts a primitive to its corresponding wrapper reference. Unboxing converts the wrapper to the primitive value and throws NullPointerException if the reference is null. Do not rely on wrapper object identity for numeric comparisons.

Formal Syntax & Structure

java syntaxjava
Integer wrapped = primitive; int primitive = wrapped;

Working Example

Example Snippetjava
public class Main {    public static void main(String[] args) {        Integer wrapped = 18;        int number = wrapped;        System.out.println(number * 2);    }}
Java Reference