Enumeration接口本身不是一个数据结构。但是,对其他数据结构非常重要。 Enumeration接口定义了从一个数据结构得到连续数据的手段。例如,Enumeration定义了一个名为nextElement的方法,可以用来从含有多个元素的数据结构中得到的下一个元素。
Enumeration接口提供了一套标准的方法,由于Enumeration是一个接口,它的角色局限于为数据结构提供方法协议。下面是一个使用的例子:
//e is an object that implements the Enumeration interface while (e.hasMoreElements()) { Object o= e.nextElement(); System.out.println(o); }实现该接口的对象由一系列的元素组成,可以连续地调用nextElement()方法来得到 Enumeration枚举对象中的元素。Enumertion接口中仅定义了下面两个方法。
·boolean hasMoreElemerts()
测试Enumeration枚举对象中是否还含有元素,如果返回true,则表示还含有至少一个的元素。
·Object nextElement()
如果Bnumeration枚举对象还含有元素,该方法得到对象中的下一个元素。