0
0
Javaprogramming~15 mins

Unboxing 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 unbox the Integer object to an int primitive.

Java
Integer num = 10;
int value = num[1];
🎯 Drag options to blanks, or click blank then click option
A.toString()
B.valueOf()
C.intValue()
D.doubleValue()
Attempts:
3 left
2fill in blank
medium

Complete the code to assign the unboxed Double value to a double variable.

Java
Double d = 5.5;
double val = d[1];
🎯 Drag options to blanks, or click blank then click option
A.toString()
B.intValue()
C.floatValue()
D.doubleValue()
Attempts:
3 left
3fill in blank
hard

Fix the error in unboxing the Boolean object to a boolean primitive.

Java
Boolean flag = Boolean.TRUE;
boolean isTrue = flag[1];
🎯 Drag options to blanks, or click blank then click option
A.booleanValue()
B.intValue()
C.toString()
D.doubleValue()
Attempts:
3 left
4fill in blank
hard

Fill both blanks to unbox the Character object and compare it to a char literal.

Java
Character ch = 'a';
if (ch[1] == '[2]') {
    System.out.println("Match");
}
🎯 Drag options to blanks, or click blank then click option
A.charValue()
Ba
Cb
D.toString()
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a map with unboxed keys and values from wrapper objects.

Java
Map<Integer, Double> map = new HashMap<>();
Integer key = 1;
Double value = 2.5;
map.put(key[1], value[2]);

for (Map.Entry<Integer, Double> entry : map.entrySet()) {
    int k = entry.getKey();
    double v = entry.getValue();
    System.out.println(k [3] v);
}
🎯 Drag options to blanks, or click blank then click option
A.intValue()
B.doubleValue()
C+
D-
Attempts:
3 left