0Pricing
Java Academy · Lesson

Autoboxing and Unboxing

Automatic conversion rules.

Automatic Conversion

Autoboxing is Java automatically converting a primitive into its wrapper object. Unboxing is the reverse, turning a wrapper back into a primitive.

This happens silently so you can mix the two worlds without manual conversion calls.

Boxing in Action

Assigning an int to an Integer variable triggers autoboxing. The compiler inserts a call to Integer.valueOf for you.

public class Main {
    public static void main(String[] args) {
        int primitive = 42;
        Integer boxed = primitive;
        System.out.println(boxed);
    }
}

All lessons in this course

  1. Primitive vs Wrapper Types
  2. Autoboxing and Unboxing
  3. Parsing and Valueof
  4. Autoboxing Pitfalls
← Back to Java Academy