| Author |
getting the values from arraylist
|
Raj chiru
Ranch Hand
Joined: Aug 12, 2008
Posts: 140
|
|
Hi...
if you can store 100,000 elements(or values) in arraylist ,How to get(or iterate) particular element(or value) from arraylist? and consider the performance issue .
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Raj, it is not "lackh", it is lakh i.e. hundred thousand.
Now you said, that you want to iterate over some particular elements. What is the criteria that you have for selecting the elements??
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
If the ArrayList is sorted, then you can us a binarySearch. With 100,000 elements, it will take a maximum of 17 comparisons.
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
And if there is a serious performance issue here, then perhaps the decision to use an ArrayList should be revisited. Using a Set makes the search an O(1) operation, instead of O(N) for an unsorted list and O(log N) for a sorted list.
|
 |
 |
|
|
subject: getting the values from arraylist
|
|
|