tg-me.com/topJavaQuizExplain/208
Last Update:
What is the output of the code snippet?
❌ A. [1, 2]
✅ B. [1]
❌ C. [2]
❌ D. []
❌ E. The code does not compile
❌ F. None of the above
Explanation:
Be careful when autoboxing into Integer. It actually outputs [1]. After adding the two values, the List contains [1, 2]. We then request the element with index 1 be removed. That’s right: index 1. Because there’s already a remove() method that takes an int parameter, Java calls that method rather than autoboxing. If you want to remove the 1, you can write numbers.remove(new Integer(1)) to force wrapper class use.
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/topJavaQuizExplain/208