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.

Ruhul said:   1 decade ago
In arrayList The colection are ordered in which order they are inserted.

David Sinclair said:   1 decade ago
I think this question might have a wrong answer. I see no mention of ordering in the docs and as John says above testing it shows it not to be ordered.

John said:   1 decade ago
In what way are they ordered?
I run:

java.util.ArrayList<Integer> al = new java.util.ArrayList<Integer>();
al.add(4);
al.add(3);
al.add(5);

for (Integer i : al) {
System.out.println(i);
}

And I get
4
3
5
as output. Is that ordered?


Post your comments here:

Your comments will be displayed after verification.