A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
Java in General
Is accessing ArrayList through Index consistent?
Joined: Oct 10, 2005
Apr 25, 2010 10:10:14
I have a very basic question. Imagine I have an arrayList that has Strings
arrStr = new ArrayList() arrStr.add("First"); arrStr.add("Second"); . . . . . . arrStr.add("Ten");
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,
Joined: Apr 10, 2010
Apr 25, 2010 10:18:24
Yes. If you use that version of add method of class
you can be sure that your
will be at index
(if the list was empty before the add)
Joined: May 26, 2003
Apr 25, 2010 10:19:44
Yes. Assuming nobody updates the first item. If I add a new item using the index "0", it will then be the first item.
How To Ask Questions The Smart Way
Blogging on Certs:
SCEA Part 1
Part 2 & 3
Core Spring 3
TOGAF part 1
I agree. Here's the link:
subject: Is accessing ArrayList through Index consistent?
Swap sublist of an arraylist with the sublist of another arraylist
Undetectable error in code
LinkedList/ArrayList: need a hybrid
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013