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
How we can skip finally block of exception even if some exception occurs in the exception block in java?
Does string isempty check for null?
Why does my function print none?
Can we overload run() method in java?
What must a class do to implement an interface in java programming?
Can a class be declared as static?
What is the base class for error and exception?
Does importing a package imports its sub-packages as well in java?
How to do encapsulation in java?
What is the difference between final, finally and finalize() in java?
What is difference between c++ and java ?
What is the purpose of encapsulation?
What is the purpose of the finalize() method?
What are the differences between heap and stack memory in java?
Is null a string or object in java?