Getting an enumeration over the specified collection. This provides interoperability with legacy APIs that require an enumeration as input.
package collection.demos;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
public class GettingEnumerationOfCollection {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
Enumeration<String> e=Collections.enumeration(list);
while(e.hasMoreElements()){
System.out.println(e.nextElement());
}
}
}
/*
OUTPUT :
A
B
C
D
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
public class GettingEnumerationOfCollection {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
Enumeration<String> e=Collections.enumeration(list);
while(e.hasMoreElements()){
System.out.println(e.nextElement());
}
}
}
/*
OUTPUT :
A
B
C
D
*/
Comments