首页 > 代码库 > LinkedList的使用

LinkedList的使用

package zxd.work615;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class TestLinkedList {
public static void main(String[] args) {
FirstNews new1 = new FirstNews("1","中考新闻","刘伦",new Date());
FirstNews new2 = new FirstNews("2","高考新闻","大鹏",new Date());
FirstNews new3 = new FirstNews("3","刘伦撞猪","毛东",new Date());
FirstNews new4 = new FirstNews("4","帅帅倾城一笑","周帅",new Date());

LinkedList<FirstNews> list = new LinkedList<FirstNews>();
list.add(new1);
list.add(new3);
list.addFirst(new4);
list.addLast(new2);
print(list);
System.out.println("删除测试");
list.remove();//删第一个
list.removeFirst();
list.removeLast();

}
public static void print(LinkedList<FirstNews> list){
for (FirstNews f : list) {
System.out.println(f.getId());
}
}
}

LinkedList的使用