zoukankan      html  css  js  c++  java
  • JAVA 的Enumeration(列举)

    Enumeration是java.util中的一个接口类,在Enumeration中封装了有关枚举数据集合的方法。   

    public interface Enumeration<E> {    
    
     /**      
    
    * Tests if this enumeration contains more elements.      
    
    *     
    
     * @return  <code>true</code> if and only if this enumeration object      
    
    *           contains at least one more element to provide;      
    
    *          <code>false</code> otherwise.     
    
     */ 
    
     
    
    boolean hasMoreElements();
    
    /**      
    
    * Returns the next element of this enumeration if this enumeration      
    
    * object has at least one more element to provide.      
    
    *      
    
    * @return     the next element of this enumeration.      
    
    * @exception  NoSuchElementException  if no more elements exist.      
    
    */     
    
    E nextElement();   
    
    }
    

     public interface Enumeration<E>  实现Enumeration接口的对象,它生成一系列元素,一次生成一个。

    Enumeration有两个方法:

    hasMoreElements()   测试此枚举是否包含更多的元素。

    nextElement()           如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。连续调用 nextElement 方法将返回一系列的连续元素。

    例如,要输出 Vector<E> v 的所有元素,可使用以下方法:

    for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
    
    System.out.println(e.nextElement());

    这些方法主要通过向量的元素、哈希表的键以及哈希表中的值进行枚举。枚举也用于将输入流指定到 SequenceInputStream 中。

    注:此接口的功能与 Iterator 接口的功能是重复的。

    此外,Iterator 接口添加了一个可选的移除操作,并使用较短的方法名。新的实现应该优先考虑使用 Iterator 接口而不是 Enumeration 接口。

  • 相关阅读:
    菜鸟小试牛刀。。
    RDBMS中部分关于可用性的特性
    ORA01403:no data found exception的解决小道
    oracle的存储结构(一)
    过度使用DBLINK带来的问题
    如何远程指定查询分区表的某个分区
    oracle显式游标不关闭、不关闭就再次打开会不会报错?
    Http方式下载Servlet实现
    Javazip压缩文件乱码问题
    mysql “Access denied for user 'root'@'localhost'
  • 原文地址:https://www.cnblogs.com/haoge520/p/4832810.html
Copyright © 2011-2022 走看看