ArrayList-Linked-Set的迴圈中刪除資料的錯誤顯示

瓜瓜東西發表於2014-08-15
package com.wanju.project001.zonghe.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class TestListSet {

	public static void main(String[] args) {
		TestListSet t = new TestListSet();
		t.init();
	}
	
	public void init(){
		Set<Integer> set = new HashSet<Integer>();
		List<Integer> list = new ArrayList<Integer>();
		List<Integer> list2 = new LinkedList<Integer>();
		 
		for (int i = 0; i < 6; i++) {
		    set.add(i);
		    list.add(i);
		    list2.add(i);
		}
		 
		for (int i = 0; i < 3; i++) {
		    set.remove(i);
		    list.remove(i);
		    list2.remove(i);
		    System.out.println();
		}
		 
		System.out.println("removed set: "+set.toString());
		System.out.println("removed list: "+list.toString());
		System.out.println("removed list: "+list2.toString());
	}
}
removed set: [3, 4, 5]
removed list: [1, 3, 5]
removed list: [1, 3, 5]


相關文章