import
java.util.*;
class VectorEx
{
public static
void main(String args[])
{
Vector list=new
Vector();
list.add(10);
list.insertElementAt(20,0);
list.insertElementAt(30,1);
list.add("Hello
World!");
if(list.isEmpty()==true)
System.out.println("List
is empty.");
else
System.out.println("List
is not empty.");
System.out.println("List
is: "+list);
System.out.println("First
element is: "+list.firstElement());
System.out.println("Last
element is: "+list.lastElement());
System.out.println("List
size is: "+list.size());
System.out.println("Element
at location 1: "+list.elementAt(1));
list.removeElementAt(1);
System.out.println("Removed
element: 30");
System.out.println("List
is: "+list);
}
}
OUTPUT:
C:\Program
Files\Java\jdk1.7.0\bin>java VectorEx
List is not
empty.
List is: [20,
30, 10, Hello World!]
First element
is: 20
Last element
is: Hello World!
List size is: 4
Element at
location 1: 30
Removed
element: 30
List is: [20,
10, Hello World!]
No comments:
Post a Comment