import java.util.ArrayList; import java.util.Iterator; public class CollectionIterator { public static void main(String[] args) { ArrayList <Integer> list = new ArrayList<> (); list.add(50); Integer[] fruit = {10,60,20,90 }; for(Integer p : fruit) list.add(p); System.out.println("Number : "+ list); Iterator<Integer> itera = list.iterator(); while(itera.hasNext()){ int num = itera.next(); if (num >= 50) itera.remove(); } System.out.println("Number : "+ list); } }執行結果
沒有留言:
張貼留言