aspose file tools
The moose likes Java in General and the fly likes getting the values from arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "getting the values from arraylist" Watch "getting the values from arraylist" New topic
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
    
    2

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
    
    2

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting the values from arraylist
 
Similar Threads
How to print values
Result set / Arraylist
getting unique values from an arraylist
validating the arraylist values in struts
iterate problem in struts2