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

Explain wait(), notify() and notifyall() methods of object class ?

833


What is the difference between numeric and integer?

756


What is thread safe in java?

753


Can you explain the private protected field modifier?

800


Is space a character in java?

784


What are 5 boolean operators?

849


Garbage collection in java?

790


How to declare an arraylist in java?

717


Is arraylist sorted in java?

742


Which is easier .net or java?

863


What is called module?

772


How do you square a number in java?

794


How to display names of all components in a Container?

2720


How can you read content from file in java?

812


What is static keyword in java?

770