0% found this document useful (0 votes)
69 views2 pages

Program - Demo of Vector Operation

This document demonstrates operations on a Vector in Java, including initializing a Vector with a size and increment, adding elements, checking capacity, retrieving first/last elements, checking if an element exists, enumerating elements, getting the index of an element, retrieving an element by index, inserting an element, and enumerating elements again. It creates a Vector, adds Integers and Doubles, prints out details at each step, and inserts a new element to show modification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views2 pages

Program - Demo of Vector Operation

This document demonstrates operations on a Vector in Java, including initializing a Vector with a size and increment, adding elements, checking capacity, retrieving first/last elements, checking if an element exists, enumerating elements, getting the index of an element, retrieving an element by index, inserting an element, and enumerating elements again. It creates a Vector, adds Integers and Doubles, prints out details at each step, and inserts a new element to show modification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

/* Program to demonstrates various Vector Operation */

import [Link].*;
class VectorDemo
{
public static void main(String args[ ])
{
// initial size is 4, increment is 2
Vector v = new Vector(4,2);

[Link]("Initial size : "+[Link]());


[Link]("Initial Capacity : "+[Link]());

[Link](new Integer(1));
[Link](new Integer(2));
[Link](new Integer(3));
[Link](new Integer(4));
[Link](new Integer(5));

[Link]("Capacity after five additions : "+[Link]());


[Link](new Double(5.25));
[Link]("Current Capacity : "+[Link]());
[Link](new Double(10.28));
[Link](new Integer(8));

[Link]("Current Capacity : "+[Link]());


[Link](new Float(20.25));
[Link](new Integer(10));

[Link]("Current Capacity : "+[Link]());


[Link](new Integer(11));
[Link](new Integer(12));

[Link]("\nFirst element :"+(Integer)[Link]());


[Link]("Last element :"+(Integer)[Link]());

if([Link](new Double(5.20)))
[Link]("Vector contains 5.20");

//****** Enumerate the elements in the Vector *********


Enumeration vEnum = [Link]();

[Link]("\n Elements in vector :");


while([Link]())
[Link]([Link]() +" ");
[Link]();
[Link]("index of: 11 "+[Link](11));
[Link]("element at 5:"+[Link](5));

[Link](new Integer(100), 5);

Enumeration vEnum1 = [Link]();


[Link]("\n Elements in vector :");
while([Link]())
[Link]([Link]() +" ");
[Link]();

}
}

/*Output:
Initial size : 0
Initial Capacity : 4
Capacity after five additions : 6
Current Capacity : 6
Current Capacity : 8
Current Capacity : 10

First element :1
Last element :12

Elements in vector :
1 2 3 4 5 5.25 10.28 8 20.25 10 11 12
index of: 11 10
element at 5:5.25

Elements in vector :
1 2 3 4 5 100 5.25 10.28 8 20.25 10 11 12*/

You might also like