An alternative to the Vector container

Ok I have been using Vector arrays for storing data objects. Inserting them and recalling them from a database for example. I believe vectors have a limit of something like 900 entries allowed in them. A problem I forsee in the future. So to this end I need an alternative container. Any suggestions?
bhessionAsked:
Who is Participating?
 
enachemcCommented:
vector = synchronized ArrayList
if you do not use threads, use ArrayList
ArrayList and Vector do not have a maximum size (they auto increase their capacity, which is only limited by the VM size)
0
 
colr__Commented:
Take a look at ArrayList
0
 
colr__Commented:
Yeh, I'd never heard about the max size issue either tbh. ArrayList was just an alternative to Vector. There is a whole bunch of classes in the collections package that might be of use to you. You might also want to consider a custom data structure, depending on your usage.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
bhessionAuthor Commented:
Ok can you point me to a good place to learn how to use this array list. Also as I am pulling from a very large database maybe 100,000 rows should I be concerned by using an ArrayList?
0
 
colr__Commented:
No, there are no size limits on these structures. And you use ArrayList in the same way you have done a Vector:

List<String> myList = new ArrayList<String>();
myList.add("value");

However, you should not be pulling such large numbers at the same time. If you need to actually work on such a large data set you should pull the data in stages - pull 10 rows at a time, process it, then move on to the next 10 rows until you are done. This would optimise the process as otherwise you are always going to run into possible memory and performance problems.
0
 
colr__Commented:
... plus pulling 100,000 from your database is going to grind it to a halt, nevermind your application logic.
0
 
enachemcCommented:
if you know an approximative number of records to store, use the following contructor:
List<String> myList = new ArrayList<String>(no_of_items);

no_of_items should exceed the required capacity (otherwise, ArrayList will expand its size, but at a cost of slowing you down a tiny bit)
0
 
bhessionAuthor Commented:
Sorry enachemc, could you expand on the below so I could better understand what you mean.

"no_of_items should exceed the required capacity (otherwise, ArrayList will expand its size, but at a cost of slowing you down a tiny bit)"

I'm unsure as to what your saying. Thanks
0
 
colr__Commented:
When you construct an ArrayList using the constructor new ArrayList(5), this sets up the list with an initial expected size of 5. The implementation of ArrayList uses an array in the background, so using this constructor sets the array size to 5. If you try and add a 6th item to the list, this results in a new array is constructed, the values copied across and the new value added - this alll happens at a cost because you are copying the array. Setting the initial size means you can potentially avoid this copying step.
0
 
enachemcCommented:
that is true
so ensure a correct estimate
an incorrect estimate would still work, but 0.1% slower
0
 
objectsCommented:
There is no size restriction on Vectors, they can hold the same amount an ArrayList does.
0
 
bhessionAuthor Commented:
Thanks guys.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.