Link to home
Start Free TrialLog in
Avatar of corback
corback

asked on

Best choice for a collection list

Hi, I'm actually using a vector to store objects. The problem is that i store between 15 000 and 50 000 objects and the time of storage is way too much. Is there a better type of collection than Vector to store my objects. The collection has to work like a queue and i don t do item search.
Thank you
Avatar of shji1
shji1

Try ArrayList.
--Shaji
Avatar of girionis
 Even though Vector is part of the Java Collection Framework (and the collection framework is not synchronized) Vector *is* synchronized. So if your application needs not to be thread safe I sugegst you use an ArrayList which, if you need synchronization in the future, you can always synchronize.

 If you want to give even greater flexibility to your application, I suggest you use the List interface:

  List myList = new ArrayList();

  So if your needs change in the future you could also do a

  List myList = new Vector();

  since Vector implements List.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of corback

ASKER

I ve already tried to use an arrayList but the performance are the same. In fact all i need is a list working like a "simple linked list" in C.  
Well, i've already suggested that ;-)

(java.util.LinkedList)
Avatar of corback

ASKER

I ve already tried to use an arrayList but the performance are the same. In fact all i need is a list working like a "simple linked list" in C.  
Avatar of corback

ASKER

I ve already tried to use an arrayList but the performance are the same. In fact all i need is a list working like a "simple linked list" in C.  
Please review your code, corback, I tried and a LinkedList or an ArrayList is 2ce as fast as a Vector!
;JOOP!
Avatar of corback

ASKER

oops sorry for the message :), refresh is not a good thing to do :)
I ve tried linkedList and same problem : to add 15 000 elements to a list/arrayList/Vector i need 5 seconds ... but unfortunatly i have to do it in about 2 seconds :(
Thank you all for your help
 Have you tried a simple array?
How about writing your own List?
You're saying what exactly? It's taking you 5 seconds to add 15000 object references to a LinkedList or it's taking you 5 seconds to do this after doing other things as well?
Avatar of corback

ASKER

i m really sorry in fact the problem didnt come from the insertion into the list ... i m really sorry to have disturbed you
Have a nice day
Avatar of corback

ASKER

Thank you for your support :)
>>i m really sorry in fact the problem didnt come from the insertion into the list

That's ok. I'd take a guess that somebody's told you 'Java is slow' in the past ;-)