Showing posts with label Vector Operations. Show all posts
Showing posts with label Vector Operations. Show all posts

Tuesday, August 21, 2012

Vector Operations Using Java Programming


import java.util.Iterator;
import java.util.Vector;

public class VectorOperations {

public static void main(String args[]){
Vector vt=new Vector();

vt.add(21);
vt.add(12);
vt.add(57);
vt.add(29);
vt.add(43);

System.out.println("Vector"+vt);

//Adding elements in Vector
vt.add(2, 25);
System.out.println("Vector"+vt);
vt.addElement(23);
System.out.println("Vector"+vt);

//Vector Operations.
System.out.println("Capacity"+vt.capacity());
System.out.println("Conatains 43:"+vt.contains(43));
System.out.println("First element"+vt.firstElement());
System.out.println("Value at Index 4: "+vt.get(4));
System.out.println("Remove value at 3"+vt.remove(3));

vt.add(43);
vt.add(45);
vt.add(46);
vt.add(47);
vt.add(48);
vt.add(49);
vt.add(32);
vt.add(33);
vt.add(34);

System.out.println("Vector Elements afte insertion more than 10 elements");
Iterator it=vt.iterator();
while(it.hasNext())
System.out.print(" "+it.next());
}

}


Output:

Vector[21, 12, 25, 57, 29, 43, 23]
Capacity10
Conatains 43:true
First element21
Value at Index 4: 29
Remove value at 357
Vector Elements afte insertion more than 10 elements
 21 12 25 29 43 23 43 45 46 47 48 49 32 33 34