码迷,mamicode.com
首页 > 编程语言 > 详细

Java中Enumeration接口的用法

时间:2019-01-29 00:30:40      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:bsp   nbsp   smo   tab   lse   种类   遍历   name   print   

Enumeration是java.util中的一个接口类,在Enumeration中封装了有关枚举数据集合的方法,与Iterator差不多,用来遍历集合中的元素  但是枚举Enumeration只提供了遍历Vector和Hashtable类型集合元素的功能,这种类型的集合对象通过调用elements()方法获取一个Enumeration对象  然后Enumeratino对象再调用以下方法来对集合中的元素进行遍历。

hasMoreElements():判断Enumeration对象中是否还有数据

nextElement():获取Enumeration对象中的下一个数据

实例如下:

Enumeration req = request.getParameterNames();
 while (req.hasMoreElements()) {
     Object obj = (Object) req.nextElement();
     if (obj.toString().trim().equals("LastPage")) {   
         System.out.println("LastPage \n");
     } else if (obj.toString().trim().equals("NextPage")) {
        System.out.println("NextPage");
     }
 }

Java中Enumeration接口的用法

标签:bsp   nbsp   smo   tab   lse   种类   遍历   name   print   

原文地址:https://www.cnblogs.com/exmyth/p/10332249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!