在程序中分別創(chuàng)建不同的集合對(duì)象
? ?在程序中分別創(chuàng)建不同的集合對(duì)象(要求只能存放Integer類型或其他指定類型的元素);給集合對(duì)象分別添加多個(gè)元素;使用迭代器Iterator對(duì)象和foreach循環(huán)遍歷之前的集合元素并輸出;
? ?在程序中分別創(chuàng)建不同的集合對(duì)象(要求只能存放Integer類型或其他指定類型的元素);給集合對(duì)象分別添加多個(gè)元素;使用迭代器Iterator對(duì)象和foreach循環(huán)遍歷之前的集合元素并輸出;
2017-07-04
舉報(bào)
2017-07-04
?? ??? ?ArrayList<Integer> list = new ArrayList<Integer>();
?? ??? ?
?? ??? ?list.add(1);
?? ??? ?list.add(2);
?? ??? ?list.add(3);
?? ??? ?
?? ??? ?Iterator iterator = list.iterator();
?? ??? ?while(iterator.hasNext()){
?? ??? ??? ?Integer a = (Integer) iterator.next();
?? ??? ??? ?System.out.println(a);
?? ??? ?}
?? ??? ?
?? ??? ?for(Integer b : list){
?? ??? ??? ?System.out.println(b);
?? ??? ?}
?? ??? ?
???