遍历ArrayList
作者:
是新来的啊强呀 | 来源:发表于
2020-05-18 11:58 被阅读0次import java.util.*;
public class lwq{
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<>();
list.add(0,1);
list.add(0,2);
list.add(0,3);
list.add(0,4);
list.add(0,5);
System.out.println("长度:"+list.size());
// 遍历1
for(Integer num: list){
System.out.println(num);
}
// 遍历2
Integer[] nums = new Integer[list.size()];
list.toArray(nums);
for(Integer n: nums){
System.out.println(n);
}
// 遍历3,使用遍历器遍历
Iterator<Integer> ite = list.iterator();
while(ite.hasNext()){
System.out.println(ite.next());
}
}
}
本文标题:遍历ArrayList
本文链接:https://www.haomeiwen.com/subject/sjeeghtx.html
网友评论