java容器的一点笔记

import java.util.*;public class Test {public static void main(String[] args) throws Exception{Collection c = new HashSet();c.add("a");c.add("b");Iterator i = c.iterator();while(i.hasNext()){String value = (String)i.next();System.out.println(value);}}} 打印:a b /** boolean hasNext(); //判断游标右边是否有元素Object next(); //返回游标右边的元素并将游标移动到下一个位置void remove(); //删除左边的元素,在执行完next之后该操作只能执行一次 **/ /**remove()方法*/import java.util.*;public class Test {public static void main(String[] args) throws Exception{Collection c = new HashSet();c.add(new Integer(1));c.add(new Integer(2));Iterator i = c.iterator();while(i.hasNext()){Integer value = (Integer)i.next(); i.remove();System.out.println(c);}}}打印:[2] []