0
0
Javaprogramming~15 mins

Autoboxing in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to autobox the int value into an Integer object.

Java
int num = 10;
Integer boxedNum = [1];
🎯 Drag options to blanks, or click blank then click option
Aint
Bnew Integer(num)
CInteger.valueOf(num)
Dnum
Attempts:
3 left
2fill in blank
medium

Complete the code to unbox the Integer object to a primitive int.

Java
Integer boxedNum = 20;
int num = [1];
🎯 Drag options to blanks, or click blank then click option
AInteger.parseInt(boxedNum)
BboxedNum
C(int) boxedNum
DboxedNum.intValue()
Attempts:
3 left
3fill in blank
hard

Fix the error in autoboxing when adding a primitive int to a List of Integer.

Java
List<Integer> list = new ArrayList<>();
int num = 5;
list.add([1]);
🎯 Drag options to blanks, or click blank then click option
Anum
Bnew Integer(num)
CInteger.valueOf(num)
D"num"
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a Map with Integer keys and values using autoboxing.

Java
Map<Integer, Integer> map = new HashMap<>();
int key = 1;
int value = 100;
map.put([1], [2]);
🎯 Drag options to blanks, or click blank then click option
Akey
Bvalue
C"key"
D"value"
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a List of Integer squares using autoboxing and a for loop.

Java
List<Integer> squares = new ArrayList<>();
for (int i = 1; i <= 5; i++) {
    squares.add(i [1] [2]);
}
int firstSquare = squares.get([3]);
🎯 Drag options to blanks, or click blank then click option
A*
Bi
C0
D+
Attempts:
3 left