Question #128134

What are wrapper classes and why are they useful for ArrayLists? In your answer, include examples of autoboxing and unboxing.

Expert's answer

The wrapper class is used to convert primitive types to objects. Since ArrayList is a generic class, it can only interact with objects, which is why wrapper classes for primitive types are used.

ArrayList<Integer> list = new ArrayList<>();
list.add(1);//autoboxing
int first = list.get(0);//unboxing

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS