public class Linkedlist {
public static void main(String[]args){
LinkedList link=new LinkedList();
Shop1 one=new Shop1(001,"蘋果",3.2);
Shop1 two=new Shop1(002,"火龍果",3.88);
Shop1 three=new Shop1(003,"草莓",1.2);
Shop1 three1=new Shop1(003,"草莓",1.2);
Shop1 four=new Shop1(003,"小草",1.4);
首先建議初始化這樣
LinkedList<Shop> link = new LinkedList();
//下面是簡單操作
link.add(one);
link.add(two);
link.add(three);
link.add(three1);
link.add(four);
Iterator iterator = link.listIterator();
while(iterator.hasNext()){
Shop temp = iterator.next();//得到一個節點
System.out.println(temp);
iterator.remove();//移除當前節點
}
//上面的代碼是臨時寫的,也許有誤,其實理解linkedList是鏈式節點,增刪非常方便,而且在遍歷的時候刪除不會拋並發修改異常。