could anyone let me know what difference would it make to the program in terms of memory and program speed if i use arraylist or hastable or vectors

which of this is better program practise
declare separate vectors or arraylist for different data
or use hashtable and convert to vector when u need to do calcuations.


have some thing like

public class customer {
    public static Vector cusList = new Vector();
   void add(){

or if you have some thing like

public class CustomerList extends Hashtable{
public Vector sort(){
//returns the hastable as vector(sorted)

public class customer {
    public static CustomerList cusList = new CustomerList ();
   void add(){
   cusList.put(this.id, this);

so if i use type 2 i could always retrive data as vector if i need to do calculation or any other function in progrome which should make it faster

Vector and ArrayList are almost identical (Vector methods are synchronised but ArrayLists are not). They each hold a simple ordered list of items.
HashTable is a completely different thing; it maps keys to values. The decision whether to use Vector/ArrayList or HashTable depends on whether the data has to be retrieved by keys as opposed to a simple numerical index.
Vector and ArrayList, being much simpler, are more efficient in both CPU and memory usage.
However, you would need very large data volumes before CPU or memory usage became an issue with any of these three on a modern computer

Premature optimisation, just don't do it!

That said, both Vector and Hashtable have been superseded by more efficient alternatives and their use is generally discouraged. Use Lists and Maps instead.

What actual data structure to employ depends entirely on the data. For some situations you may have a Map of Lists, for some a List of Maps, and for others again I've had to make use of Trees of Maps of Lists of Maps.

This article has been dead for over six months. Start a new discussion instead.