Answer to Question #128134 in Java | JSP | JSF for Yann

Question #128134
What are wrapper classes and why are they useful for ArrayLists? In your answer, include examples of autoboxing and unboxing.
1
Expert's answer
2020-08-02T15:27:12-0400

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS