| Author |
Is accessing ArrayList through Index consistent?
|
Raghusham Sankargal
Ranch Hand
Joined: Oct 10, 2005
Posts: 59
|
|
Hi Ranchers,
I have a very basic question. Imagine I have an arrayList that has Strings
Can the arraylist guarantee accessing it through index gives me the same result all the time? In the above example if I say arrStr.get(0). Does this give "First" always???
Thanks in advance,
Sham.
|
Raghusham Sankargal
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
|
Yes. If you use that version of add method of class ArrayList you can be sure that your String First will be at index 0 (if the list was empty before the add)
|
Bye,
Nicola
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
Sham,
Yes. Assuming nobody updates the first item. If I add a new item using the index "0", it will then be the first item.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Is accessing ArrayList through Index consistent?
|
|
|