Enumeration
In this chapter you will learn:
Get Enumeration from collection, create list from Enumeration
static<T> Enumeration<T> enumeration(Collection<T> c)
Returns an enumeration for a collection.static<T> ArrayList<T> list(Enumeration<T> e)
Create an ArrayList from an enumeration.
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
/*from java 2 s . c o m*/
public class Main {
public static void main(String args[]) throws Exception {
Vector<String> v = new Vector<String>();
v.add("a");
v.add("b");
v.add("java2s.com");
Collection<String> col = v;
Enumeration<String> e = Collections.enumeration(col);
for (; e.hasMoreElements();) {
Object o = e.nextElement();
System.out.println(o);
}
}
}
The output:
Next chapter...
What you will learn in the next chapter: