publicclass Test {publicstaticvoidmain(String[] args) { List list =newArrayList(); list.add("好好学习"); list.add("天天向上"); list.add("不做码农");//1.增强for// for(String s : list)// System.out.println(s);//2.Iterator// Iterator i = list.iterator();// while(i.hasNext())// System.out.println(i.next());//3.我偶然看到的,觉得很强。。。// for(Iterator i = list.iterator(); i.hasNext();)// System.out.println(i.next());//4.forEach的Lambda表达式实现// list.forEach(a -> System.out.println(a));//5.forEach的内部类实现// list.forEach(new Consumer<String>() {//// @Override// public void accept(String t) {// System.out.println(t);// }// });//6.我写了那么多,把这个给忘了。。// for(int i = 0; i < list.size(); i++)// System.out.println(list.get(i));//7.ListIterator实现,是Iterator的// ListIterator<String> listi = list.listIterator();// while(listi.hasNext())// System.out.println(listi.next());//8.和上面第三条思路一样for(ListIterator listi = list.listIterator(); listi.hasNext();) System.out.println(listi.next()); }}
网友评论