1 package com.lanxi.demo1_8; 2 import java.util.Iterator; 3 import java.util.LinkedList; 4 public class Test { 5 public static void main(String[] args) { 6 LinkedList link=new LinkedList(); 7 for (int i = 1; i <= 10; i++) { 8 link.add("小样"+i); 9 } 10 System.out.println("删除前集合:"); 11 Iterator it=link.iterator(); 12 while(it.hasNext()){ 13 System.out.print(it.next()+" "); 14 } 15 System.out.println(); 16 System.out.println("删除前集合大小:"+link.size()); 17 for(int i=9;i>=0;i-=2){ 18 //移除偶数对象 19 link.remove(i); 20 } 21 System.out.println(); 22 System.out.println("删除后集合:"); 23 for (int i = 0; i < link.size(); i++) { 24 System.out.print(link.get(i)+" "); 25 } 26 System.out.println("删除后集合大小:"+link.size()); 27 } 28 }
运行结果