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
Explain wait(), notify() and notifyall() methods of object class ?
What is the difference between numeric and integer?
What is thread safe in java?
Can you explain the private protected field modifier?
Is space a character in java?
What are 5 boolean operators?
Garbage collection in java?
How to declare an arraylist in java?
Is arraylist sorted in java?
Which is easier .net or java?
What is called module?
How do you square a number in java?
How to display names of all components in a Container?
How can you read content from file in java?
What is static keyword in java?