presearch
Write a Java Program to implement Vector class and its methods. | Tech Hindi Sagar
Rajnish kumar

Tech Hindi Sagar

Tech Hindi Sagar website Is Stunning Website Created For Educational Purposes. it Archive And Support Student And Teacher Learning,Facilitating, Questioning And By Providing Contexts For Engaging In Higher-Order Thinking.The Use Of Blogs Has Become Popular In Education Institutions Including Public Schools And Colleges. Blogs Can Be Useful Tools For Sharing Information And Tips Among Co-Workers, Providing Information For Students, Or Keeping In Contact With Parents.
Home Project Tutorial Videos Quiz
All Tutorial will be uploaded as soon as posible .Our Vision is Fun and Free Education for ALL Our Mission To bring all feasible courses , online..

Write a Java Program to implement Vector class and its methods.

Write a Java Program to implement Vector class and its methods.

import java.lang.*;
import java.util.Vector;
import java.util.Enumeration;
class vectordemo
{
public static void main(String arg[])
{
Vector v=new Vector();
v.addElement("one");
v.addElement("two");
v.addElement("three");
v.insertElementAt("zero",0);
v.insertElementAt("oops",3);
v.insertElementAt("four",5);
System.out.println("Vector Size :"+v.size());
System.out.println("Vector apacity :"+v.capacity());
System.out.println(" The elements of a vector are :");
Enumeration e=v.elements();
while(e.hasMoreElements())

System.out.println(e.nextElement() +" ");
System.out.println();
System.out.println("The first element is : " +v.firstElement());
System.out.println("The last element is : " +v.lastElement());
System.out.println("The object oops is found at position : "+v.indexOf("oops"));
v.removeElement("oops");
v.removeElementAt(1);
System.out.println("After removing 2 elements ");
System.out.println("Vector Size :"+v.size());
System.out.println("The elements of vector are :");
for(int i=0;i<v.size();i++)
System.out.println(v.elementAt(i)+" ");
}
}


OUTPUT:-

C:\jdk1.6.0_26\bin>javac vectordemo.java
C:\jdk1.6.0_26\bin>java vectordemo
Vector Size :6
Vector apacity :10
The elements of a vector are :
zero
one
two
oops


three
four
The first element is : zero
The last element is : four
The object oops is found at position : 3
After removing 2 elements
Vector Size :4
The elements of vector are :
zero
two
three
four
SHARE

About Admin of the Blog:

Rajnish kumar is the CEO/founder of Tech Hindi Sagar .He is a Computer Science Engineer ,Web Designer,Web Developer and a Pro Blogger..Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment