Java Programming - Objects and Collections - Discussion

Discussion Forum : Objects and Collections - Pointing out the correct statements (Q.No. 8)
8.
Which statement is true for the class java.util.ArrayList?
The elements in the collection are ordered.
The collection is guaranteed to be immutable.
The elements in the collection are guaranteed to be unique.
The elements in the collection are accessed using a unique key.
Answer: Option
Explanation:

Yes, always the elements in the collection are ordered.

Discussion:
13 comments Page 2 of 2.

Zoltan B. said:   1 decade ago
I would also say that the statement "the elements in the collection are ordered" is deceiving or at least not very clear. They certainly keep their position as long as only insertions are performed on the list (which is of course not guaranteed and the question doesn't say anything about how it will be used). But they most certainly will not be in their natural ordering.

B and C are definitely false. So answer D seems the most correct. All elements have a unique key (namely their index). Although if we consider multiple int's with the same values, than perhaps this statement is a bit problematic as well.

AAKASH KUMAR said:   9 years ago
How can be an element in the order of ArrayList?

Prakash VL said:   9 years ago
Wrong Answer!

ArrayList elements are indexed. :)


Post your comments here:

Your comments will be displayed after verification.