Enumeration接口的用法

Enumeration接口的用法

标签: iteratorvector
 分类:

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

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

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

如:

Enumeration names = request.getHeaderNames(); 

while(names.hasMoreElements()){

String name = (String)names.nextElement();

out.println("<b>"+  name +":</b>"+ request.getHeader(name) +"<br />");  if(name.equals("user-agent")){

 

out.println("<a href='#'>"+name+":"+request.getHeader(name)+"</a><br />");

 

}

 

 

 

表头输出结果:

host:localhost:8080    //端口号

connection:keep-alive  //

user-agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19  //浏览器信息

user-agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19

accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  //浏览器支持格式

accept-encoding:gzip,deflate,sdch      //

accept-language:zh-CN,zh;q=0.8

accept-charset:GBK,utf-8;q=0.7,*;q=0.3

Cookie:account=Helloween   //用户当前的状态

Referer:http://www.baidu.com  //从哪个页面单击进入的

posted @ 2016-01-23 11:58  苍狼哂啡  阅读(471)  评论(0编辑  收藏  举报