Java - Wrapper Classes

Wrapper Classes

Integer x = 10; // boxing
int y = x;     // unboxing (beware null!)

Use wrappers when generics/collections require reference types, or to represent nullability.

Try it

  1. Demonstrate NullPointerException from unboxing a null Integer and then guard against it.
  2. Store primitives vs wrappers in a list and note the boxing overhead implications.