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
What is this () in java?
Is java still necessary?
When will we use them?
What is gc()?
What is the string function?
Can we override a variable in java?
What is the difference between static class and normal class?
What is class level lock ?
If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?
What do you mean by byte code?
What are the characteristics of Final,Finally and Finalize keywords.
What is a boolean expression in java?
What do you understand by overloading and overriding in java?
What does a za z0 9 mean?
What is variable explain with example?