首页 > 其他 > 详细

集合的三种遍历方式

时间:2017-05-07 22:54:41      阅读:297      评论:0      收藏:0      [点我收藏+]

1、for循环

代码实现:

for(int i=0;i<list.size();i++){

product p=list.get(i);

System.println(p);

}

2、迭代器

Iterator<product> it = list.iterator();//product是一个类

whlie(it.hasNext());{//判断是否有下一个元素

product t=it.next();//得到下一个元素

system.println(t);

}

3、for each循环

for(product p : list){

sysrtem.println(p);

}

集合的三种遍历方式

原文:http://www.cnblogs.com/damimao/p/6819280.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!