package com.lanxi.demo1_8;
import java.util.Iterator;
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
LinkedList link=new LinkedList();
for (int i = 1; i <= 10; i++) {
link.add("小样"+i);
}
System.out.println("删除前集合:");
Iterator it=link.iterator();
while(it.hasNext()){
System.out.print(it.next()+" ");
}
System.out.println();
System.out.println("删除前集合大小:"+link.size());
for(int i=9;i>=0;i-=2){
//移除偶数对象
link.remove(i);
}
System.out.println();
System.out.println("删除后集合:");
for (int i = 0; i < link.size(); i++) {
System.out.print(link.get(i)+" ");
}
System.out.println("删除后集合大小:"+link.size());
}
}
运行结果