Enumeration output

  Enumeration is the time to use JDK1.0 output interface, the output interface is mainly to provide an output Vector class service, has been to follow the development of the JDK, Enumeration still only a Vector class service. If you want to get an Enumeration interface object, it must rely on methods of Vector class.

  1.获取Enumeration:public Enumeration<E> elements();

  1.1 Enumeration interface definition there are two methods of operation:

    - determining whether there is a next element: Boolean pubilc the hasMoreElements () ;

    - Get the current element; public E nextElement () ;

  Example:

package com.iterator.demo;

import java.util.Enumeration;
import java.util.Vector;

public class IteratorDemo {
    public static void main(String[] args) {
        Vector<String> all = new Vector<String>();
        all.add("hello");
        all.add("world");
        all.add("sina");
        all.add("sohu");
        Enumeration<String> enu = all.elements();
        while (enu.hasMoreElements()) {
            String string = enu.nextElement();
            System.out.print(string+"、");
        }
    }
}

operation result:

hello, world, Sina, Sohu,

 Since the appearance of the interface class a long time, so in some relatively early in the development process, there are some methods support Enumeration output operation, but with the continuous improvement class methods, most of the operations can be achieved directly Iterator.

Guess you like

Origin www.cnblogs.com/sunzhongyu008/p/11230764.html