• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting the values from arraylist  RSS feed

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the ArrayList is sorted, then you can us a binarySearch. With 100,000 elements, it will take a maximum of 17 comparisons.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!