Bird
0
0

You want to store a list of integers that may include null values to represent missing data. Which type should you use in Java?

hard📝 Application Q8 of 15
Java - Wrapper Classes
You want to store a list of integers that may include null values to represent missing data. Which type should you use in Java?
AList<int>
BList<Integer>
CList<double>
DList<Double>
Step-by-Step Solution
Solution:
  1. Step 1: Understand nullability in collections

    Primitive types like int or double cannot hold null, but wrapper classes can.
  2. Step 2: Choose correct wrapper type

    Integer is the wrapper for int and can hold null; List supports null values.
  3. Final Answer:

    List -> Option B
  4. Quick Check:

    Use wrapper types in collections to allow nulls = A [OK]
Quick Trick: Use wrapper classes in collections to allow null values [OK]
Common Mistakes:
  • Using primitive types in generics
  • Choosing wrong wrapper type
  • Assuming primitives can be null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes