Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What feature does an ArrayList have over an array?

  1. It can only store primitive types

  2. It has a fixed length

  3. It can automatically resize itself

  4. It is more memory efficient than an array

The correct answer is: It can automatically resize itself

An ArrayList has the advantage of being able to automatically resize itself while an array has a fixed length. This means that an ArrayList can grow or shrink as needed, making it more flexible and convenient for storing and managing collections of data. Option A is incorrect because an ArrayList can also store non-primitive types, such as strings or objects. Option B is incorrect because an ArrayList's length is not fixed. Option D is incorrect because an array is actually more memory efficient than an ArrayList as it does not have the overhead of automatic resizing.