遍历数组 iterator方法和for方法
来源:互联网 发布:cpu温度检测软件 编辑:程序博客网 时间:2024/05/21 07:10
遍历数组 iterator方法和for方法
下面的程序可以看出他们之间的区别与联系:
import java.util.ArrayList;import java.util.Iterator;import java.util.List;public class ArrayTest { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); System.out.println("用for循环遍历"); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } System.out.println("用增强for循环"); for (Integer i : list) { System.out.println(i); } System.out.println("用iterator+while"); Iterator<Integer> it = list.iterator(); while (it.hasNext()) { int i = (Integer) it.next(); System.out.println(i); } System.out.println("用iterator+for"); for (Iterator<Integer> iter = list.iterator(); iter.hasNext();) { int i = (Integer) iter.next(); System.out.println(i); } }}
阅读全文
0 0
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- 遍历数组 iterator方法和for方法
- java数组遍历——iterator和for方法
- java数组遍历——iterator和for方法
- java数组遍历——iterator和for方法
- java集合与数组遍历-iterator和for方法
- java数组遍历——iterator和for方法
- 数组遍历——iterator接口和for方法
- java数组遍历——iterator和for方法(精品总结)
- 三中遍历数组和集合的方法 for foreach iterator
- javaee 数组遍历 --iterator for
- 集合框架-for、foreach、Iterator三种遍历方法
- 使用each方法代替for遍历数组
- Grunt的配置和使用
- hdu 6129 Just do it(递推)
- 1054: 猴子吃桃
- 《三体》读后思考-泰勒展开/维度打击/黑暗森林
- D
- 遍历数组 iterator方法和for方法
- 继承之构造器借用法
- 神经网络学习笔记
- Android 判断网络是否可用、网络类型WIFI/2G/3G/4G及获取IP
- 100亿MongoDB瓦片出图 性能测试报告
- VBA-突出异常点
- 如何实现淘宝地址中的三级联动
- Java数据结构03----单向链表的插入和删除
- Linux vi简介以及命令