Tuesday 6 May 2014

Vector : elements : Get Elements in Enumeration format

public Enumeration<E> elements()
Returns an enumeration of the components of this vector. 

import java.util.*;

class VectorElementElements{
 public static void main(String args[]){
  Vector<String> myVector;
  Enumeration<String> myEnum;
  
  myVector = new Vector<> ();
  
  /* Add Elements to myVector */
  for(int i=1; i<6; i++)
   myVector.add("String " +i); 
   
  myEnum = myVector.elements();  
  
  while(myEnum.hasMoreElements()){
   System.out.println(myEnum.nextElement());
  }
 }
}

Output
String 1
String 2
String 3
String 4
String 5


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment