Java OCA OCP Practice Question 610

Question

Which of the following are benefits of ArrayList over an array?

Select 1 option

  • A. You do not have to worry about the size of the ArrayList while inserting elements.
  • B. It consumes less memory space.
  • C. You do not have to worry about thread safety.
  • D. It allows you to write type safe code.


Correct Option is  : A

Note

A. is correct.

An ArrayList resized dynamically at run time as per the situation.

An array cannot be resized once created.

This reduces the amount of boiler plate code that is required to do the same task using an array.

B. is wrong.

Because of additional internal data structure and pointers, it actually consumes a little more memory than an array.

C. is wrong

An ArrayList, just like an array is not thread safe.

If you have multiple threads trying to add and remove elements from an ArrayList, you have to write additional code to ensure thread safety.

D. is wrong

Since ArrayList is a generics enabled class, it helps you write type safe code.




PreviousNext

Related