-1

In my java app deployed on tomcat, about 500K items (can go even upwards) are added to ArrayList. Then, these list(s) are iterated to check some conditions.

Que- For this scenario, would using LinkedList gain performance?

Any pointers from practical experience for volume of data exceeding 200K items~ 1 million items.

Mostly list of strings and objects having multiple properties mostly string (Basically get data from DB, convert it to Java objects and send it over via HTTP) If size of data is expected to stay within 100K or less, would there be a difference

Rockoder
  • 746
  • 2
  • 11
  • 22
  • Your question is unclear: you ask the difference between a List - which is an interface - and a LinkedList - which is an implementation. – Filip Jan 20 '16 at 20:27
  • 1
    In short: the constant factors on `ArrayList` are so overwhelmingly better that `LinkedList` is almost never the right answer. – Louis Wasserman Jan 20 '16 at 21:31
  • Thanks Louis. I did look at other questions thoroughly before posting my question. I was not sure if anyone shared experience about practical production data for the volume of data I was interested in and hence the question. I guess you did not like it and decide to downvote! I can close the question if this is totally useless. – Rockoder Jan 20 '16 at 21:56
  • @Filip - Updated the question to mention ArrayList – Rockoder Jan 20 '16 at 22:11

1 Answers1

0

See this question: When to use LinkedList over ArrayList?

LinkedList allows for constant-time insertions or removals using iterators, but only sequential access of elements. In other words, you can walk the list forwards or backwards, but finding a position in the list takes time proportional to the size of the list.

ArrayList, on the other hand, allow fast random read access, so you can grab any element in constant time. But adding or removing from anywhere but the end requires shifting all the latter elements over, either to make an opening or fill the gap. Also, if you add more elements than the capacity of the underlying array, a new array (1.5 times the size) is allocated, and the old array is copied to the new one, so adding to an ArrayList is O(n) in the worst case but constant on average.

Community
  • 1
  • 1
renanleandrof
  • 6,699
  • 9
  • 45
  • 67
  • Thanks for your answer. I was looking for some practical experience in terms of estimating the time it takes to add/retrieve the Volume of data I mentioned. I did estimate for arraylist in my code but before updating code, retesting everything, thought of asking this. For the answers to other questions related to this topic, someone mentioned if one don't delete/modify the list, linkedlist can be faster. that struck me! – Rockoder Jan 20 '16 at 21:59