Two implementations of List Vector vs ArrayListSolutionvecto

Two implementations of List; Vector vs. ArrayList

Solution

vector: It is a synchronised and it uses both the enumerator and iterator to send the information. It functionality is slow because it holds multiple functions or iterations simultaneously and it is a legacy class.

Array list: It is a non synchronised class and it uses iterator to transfer the data and it is a bit fast when compare with the vector and it is a non legacy class which is used.

Let us see the difference in the implementation by taking examples.

Arraylist:

import java.util.*;    

class TestArrayList21

{    

public static void main(String args[])

{    

  List<String> al=new ArrayList<String>();    

al.add(\"raghu\");

al.add(\"ravi\");    

al.add(\"sashi\");    

al.add(\"ram\");    

Iterator itr=al.iterator();  

while(itr.hasNext())

{  

System.out.println(itr.next());  

}    

}    

}    

vector:

import java.util.*;      

class TestVector1{      

public static void main(String args[]){      

  Vector<String> v=new Vector<String>();

  v.add(\"ram\");

v.addElement(\"ahmed\");

  v.addElement(\"kiran\");  

  Enumeration e=v.elements();  

while(e.hasMoreElements()){  

  System.out.println(e.nextElement());  

}  

}      

}      

 Two implementations of List; Vector vs. ArrayListSolutionvector: It is a synchronised and it uses both the enumerator and iterator to send the information. It
 Two implementations of List; Vector vs. ArrayListSolutionvector: It is a synchronised and it uses both the enumerator and iterator to send the information. It

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site