Is there any unbounded list in Java other than linked list ? I have to store BLOB objects in a list. I am using arrayList currently but I am worried that arraylist may not be able to store(may reach max capacity) when the size of list grows. I thought of using linked list but it doesn't look efficient.
-
2What's wrong with ArrayList? I don't see anything in [its documentation](http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html) about it having a size limit. (If you're concerned about the list's "capacity", that grows automatically as new elements are added.) – Wyzard Nov 01 '12 at 00:14
-
2Unless you have over 2^31+1 objects, ArrayList or LinkedList will be fine. You'll encounter extreme memory loads with that many objects regardless. – FThompson Nov 01 '12 at 00:14
-
You can refer this similar answer here. http://stackoverflow.com/questions/3767979/how-many-data-a-list-can-hold-at-the-maximum – user1500049 Nov 01 '12 at 00:15
3 Answers
ArrayList
doesn't have any size limitation -- it'll expand as large as it has to to fit the elements you add to it.
ArrayList
might be technically limited to 2^31-1 values -- or approximately 2 billion elements -- but you'll run out of RAM first.

- 191,574
- 25
- 345
- 413
-
*"... but you'll run out of RAM first"* - or your application will grind to a halt processing doing `O(N)` operations on the monstrous list :-) – Stephen C Nov 01 '12 at 00:57
-
That's true...but it'll still be faster than a `LinkedList` would be, so eh. – Louis Wasserman Nov 01 '12 at 01:01
-
I'm not disagreeing with your point. I'm reinforcing it ... by pointing out another reason why monstrous lists simply don't work. – Stephen C Nov 01 '12 at 04:23
arraylist may not be able to store(coz of its size limitation) when the size of list grows.
What size limitation?
List<Blob> blobs = new ArrayList<Blob>();
You're only limited by the amount of memory you can allocate to the JVM or, as yshavit correctly points out below, the max integer value for the index.

- 305,152
- 44
- 369
- 561
-
1Well, technically you're limited by `Integer.MAX_VALUE` (2^31-1), since that's the largest than an array can be. But that's not going to be your limiting factor in practice. – yshavit Nov 01 '12 at 00:37
Be aware that there are dozens of Collection implementations in Java, depends exactly on your needs. ArrayList for example, doesn't have an effective size limit, cause you will have OutOfMemoryError before getting to the max size. checkout Collections page before deciding.

- 680
- 4
- 10