Results 1 to 5 of 5
- 07-31-2011, 10:11 PM #1
Member
- Join Date
- May 2010
- Posts
- 23
- Rep Power
- 0
- 07-31-2011, 10:53 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
It depends what you want to do with those lines; if you just want to process them one by one in the order they were read there is no need to store them all, otherwise a List of some form comes to mind, but, again, it depends on how you want to traverse through them and what you want to do with them.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-31-2011, 11:06 PM #3
Member
- Join Date
- May 2010
- Posts
- 23
- Rep Power
- 0
Well, I'd basically need to constantly traverse the "list" and remove items as needed. So I was thinking about using a Vector from the java.util package simply because there are predefined methods that could help me do that.
So I guess the question, is it OK to use a vector to store up to thousands of elements?
-
You could use Vector or ArrayList (which is preferred of the two) as long as you don't run out of memory, but if you need to store thousands of Strings, also consider using a database.
- 08-05-2011, 04:10 PM #5
Member
- Join Date
- Aug 2011
- Posts
- 95
- Rep Power
- 0
Generally speaking, you should not use Vector; use ArrayList instead. Vector is thread safe, which makes it slow, and you don't normally need a thread safe collection.
If the data fits in memory, I would suggest using 'java.util.LinkedList', due to your 'need to constantly traverse the "list" and remove items as needed.' Use the Lists' iterator() method and the remove() method on the Iterator. (Using 'Iterator.remove()' avoids ConcurrentModificationException.) LinkedList is much faster at adding and removing elements in the middle of the list. But beware: Methods using 'int index' are slow.
Similar Threads
-
Which data structure to use?
By malaguena in forum New To JavaReplies: 4Last Post: 04-05-2011, 04:41 PM -
Spliting Large String Data (upto 2 GB)
By piyush@java in forum Advanced JavaReplies: 5Last Post: 01-12-2011, 02:23 PM -
Storing/retrieving arrays in a data structure...
By pbandjay in forum New To JavaReplies: 0Last Post: 11-03-2010, 12:39 AM -
data structure and data base??
By ahmed13 in forum Advanced JavaReplies: 8Last Post: 03-27-2009, 05:48 AM -
Queue data structure
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks