• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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
0
corback
Asked:
corback
  • 6
  • 4
  • 2
  • +2
1 Solution
 
shji1Commented:
Try ArrayList.
--Shaji
0
 
girionisCommented:
 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.
0
 
CEHJCommented:
A LinkedList will probably be your most lightweight option
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
corbackAuthor Commented:
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.  
0
 
CEHJCommented:
Well, i've already suggested that ;-)

(java.util.LinkedList)
0
 
corbackAuthor Commented:
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.  
0
 
corbackAuthor Commented:
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.  
0
 
sciuriwareCommented:
Please review your code, corback, I tried and a LinkedList or an ArrayList is 2ce as fast as a Vector!
;JOOP!
0
 
corbackAuthor Commented:
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
0
 
girionisCommented:
 Have you tried a simple array?
0
 
shji1Commented:
How about writing your own List?
0
 
CEHJCommented:
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?
0
 
corbackAuthor Commented:
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
0
 
corbackAuthor Commented:
Thank you for your support :)
0
 
CEHJCommented:
>>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 ;-)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now