Monday, February 23, 2009

sample code to demonstrate enumeration interface



package collection;
import java.util.*;
public class EnumerationDemo {
public static void main(String ar[])
{
Vector v= new Vector();
for(int i=0;i<=10; i++)
{
v.addElement(new Integer(i));
}
System.out.println(v); // [0,1,2,3…….10]
Enumeration e=v.elements();
while(e.hasMoreElements())
{
Integer i=(Integer)e.nextElement();
if(i.intValue() % 2 ==0)
{
System.out.println(i);
}
}
}
}


output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
0
2
4
6
8
10



0 comments:

Post a Comment