Hello all,
I am trying to understand which one is better than other. I mean for our project, performance is NOT AN ISSUE, I know. But as I read through the API for the appropriate one for our project, I could'nt deciede.
I used Vectors first, but later changed to ArrayList b'se of synchronization issues in Vector. Then again, I went through K&B book for the pros and cons of each collection class.
I found the following diff. between ArrayList and LinkedList in the book.
For faster iterations, use ArrayList. If you have more additions and removals, then prefer LinkedList over ArrayList
But could'nt find how to compare between HashSet and List classes.
Actually, I may change some from ArrayList to LinkedList in my program depending on the requirements. Its ok to use different set of collection classes right?
And I also read the HashSet API. Here is one important point, atleast I think, to consider.
This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance's size (the number of elements) plus the "capacity" of the backing HashMap instance (the number of buckets). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.
Is it preferable to go for HashSet instead of ArrayList or LinkedList? I understood from above that as the size increases there will be overhead if we go for HashSet right?
Appreciate your help, thanks
