what is the difference between ArrayList and Vector

Answer Posted / tamilvendan

import java.util.*;
public class VectorDemo{
public static void main(String[] args){
Vector<Object> vector = new Vector<Object>();
int primitiveType = 10;
Integer wrapperType = new Integer(20);
String str = "tapan joshi";
vector.add(primitiveType);
vector.add(wrapperType);
vector.add(str);
vector.add(2, new Integer(30));
System.out.println("the elements of vector: " + vector);
System.out.println("The size of vector are: " +
vector.size());
System.out.println("The elements at position 2 is: " +
vector.elementAt(2));
System.out.println("The first element of vector is: " +
vector.firstElement());
System.out.println("The last element of vector is: " +
vector.lastElement());
vector.removeElementAt(2);
Enumeration e=vector.elements();
System.out.println("The elements of vector: " + vector);
while(e.hasMoreElements()){
System.out.println("The elements are: " +
e.nextElement());
}
}
}

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

811


Why is stringbuffer faster than string?

697


State differences between C and Java?

879


What is meant by binding in rmi?

773


What are conditionals and its types?

831


What is hashmap and map?

740


What is the difference between sop and work instruction?

690


What is the difference between call by reference and call by pointer?

725


What is the use of default method in interface in java? Explain

745


Why is logger singleton?

736


How do you remove duplicates from an array in java?

717


What is difference between core java and java ee?

674


Why do we need singleton class?

736


Does it matter in what order catch statements for filenotfoundexception and ioexception are written?

718


What is the difference between overriding and overloading in OOPS.

812