Complete the code to autobox the int value into an Integer object.
int num = 10; Integer boxedNum = [1];
In Java, autoboxing automatically converts a primitive int to an Integer object when assigned directly.
Complete the code to unbox the Integer object to a primitive int.
Integer boxedNum = 20; int num = [1];
Unboxing happens automatically when assigning an Integer object to an int variable.
Fix the error in autoboxing when adding a primitive int to a List of Integer.
List<Integer> list = new ArrayList<>(); int num = 5; list.add([1]);
Autoboxing allows adding a primitive int directly to a List of Integer objects.
Fill both blanks to create a Map with Integer keys and values using autoboxing.
Map<Integer, Integer> map = new HashMap<>(); int key = 1; int value = 100; map.put([1], [2]);
Autoboxing converts primitive int key and value to Integer objects when putting into the Map.
Fill all three blanks to create a List of Integer squares using autoboxing and a for loop.
List<Integer> squares = new ArrayList<>(); for (int i = 1; i <= 5; i++) { squares.add(i [1] [2]); } int firstSquare = squares.get([3]);
The code multiplies i by i to get squares, autoboxes the result when adding to the list, and retrieves the first element at index 0.
