5、LinkedList的使用
public static void main(String[] args) {
LinkedList linkedList =new LinkedList<>();
Student s1= new Student("张三",18);
Student s2= new Student("李四",20);
Student s3= new Student("王五",25);
linkedList.add(s1);
linkedList.add(s2);
linkedList.add(s3);
linkedList.remove(s1);
linkedList.remove(new Student("李四",20));
System.out.println("删除后的元素"+linkedList.size());
System.out.println(linkedList.toString());
System.out.println("===============for循环===============");
for(int i=0;i<linkedList.size();i++){
System.out.println(linkedList.get(i));
}
System.out.println("============增强for循环===============");
for(Object obj:linkedList){
System.out.println(obj);
}
System.out.println("============使用迭代器===============");
Iterator it=linkedList.iterator();
while (it.hasNext()){
System.out.println(it.next());
}
System.out.println("============使用列表迭代器===============");
ListIterator it1=linkedList.listIterator();
while (it1.hasNext()){
System.out.println(it1.next());
}
}