Moving to Java In General (Intermediate) where you will, no doubt, be told that the best way to find out about the collection classes is to read the API. http://java.sun.com/j2se/1.5.0/docs/api/index.html
when we use ArrayList, when we use Vector, When we use TreeMap, when we use HashMap, when we use Hashtable, when we use Arrays.
1. Never use Vector; always use ArrayList instead. Vector is an old class, left over from Java version 1.1. The main difference between Vector and ArrayList is that Vector is synchronized, while ArrayList is not. That makes ArrayList faster.
2. TreeMap or HashMap: Both are dictionary data structures; they allow you to store key-value pairs, and you use the keys to find the values. HashMap is unordered. In a TreeMap, elements are sorted on the keys. Sometimes that is useful in applications.
3. Hashtable: The same as with Vector; this is an old Java 1.1 class. Don't use it; use HashMap instead.
4. Arrays: An array has a fixed size. If you need a list that can grow or shrink dynamically (i.e., while the program is running), you'll need to use one of the implementations of java.util.List instead of an array.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jesper de Jong wrote:when we use ArrayList, when we use Vector, When we use TreeMap, when we use HashMap, when we use Hashtable, when we use Arrays.
1. Never use Vector; always use ArrayList instead. Vector is an old class, left over from Java version 1.1. The main difference between Vector and ArrayList is that Vector is synchronized, while ArrayList is not. That makes ArrayList faster.
2. TreeMap or HashMap: Both are dictionary data structures; they allow you to store key-value pairs, and you use the keys to find the values. HashMap is unordered. In a TreeMap, elements are sorted on the keys. Sometimes that is useful in applications.
3. Hashtable: The same as with Vector; this is an old Java 1.1 class. Don't use it; use HashMap instead.
4. Arrays: An array has a fixed size. If you need a list that can grow or shrink dynamically (i.e., while the program is running), you'll need to use one of the implementations of java.util.List instead of an array.
Great!! explanation Jesper, its really more valuable statements whatever you posted here, it'll help to understand the actual use of those for both who is learning java and also for them who's just started to work on the projects..actually some more points i also learnt from this thread..so thank you very much Jesper for this post.