0
0
Javaprogramming~15 mins

Why wrapper classes are used in Java - Test Your Understanding

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

Complete the code to create an Integer wrapper object from a primitive int.

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

Complete the code to convert a String to an Integer using wrapper class methods.

Java
Integer num = Integer.[1]("123");
🎯 Drag options to blanks, or click blank then click option
AparseInt
BvalueOf
CtoString
DintValue
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly convert an Integer to a primitive int.

Java
int value = num.[1]();
🎯 Drag options to blanks, or click blank then click option
AintValue
BtoInt
CparseInt
DvalueOf
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a list of Integer objects from an array of ints.

Java
int[] arr = {1, 2, 3};
List<Integer> list = new ArrayList<>();
for (int num : arr) {
    list.[1](Integer.[2](num));
}
🎯 Drag options to blanks, or click blank then click option
Aadd
BvalueOf
Cappend
DparseInt
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a map of String keys to Integer values where values are only added if greater than 10.

Java
Map<String, Integer> map = new HashMap<>();
for (String key : keys) {
    Integer val = Integer.[1](key.length());
    if (val [2] 10) {
        map.[3](key, val);
    }
}
🎯 Drag options to blanks, or click blank then click option
AvalueOf
B>
Cput
Dadd
Attempts:
3 left