importjava.util.LinkedList;publicclassDemo{publicstaticfinalvoidmain(String[] args){LinkedList lList =newLinkedList();System.out.println("Number of items in the list: "+ lList.size());String item1 ="foo";String item2 ="bar";String item3 ="sai";String item4 ="prasad";
lList.add(item1);
lList.add(item2);
lList.addFirst(item3);System.out.println(lList);
lList.addLast(item4);System.out.println(lList);System.out.println("Number of items in the list: "+ lList.size());}}
上面的代码示例将产生以下结果。
Number of items in the list:0[sai, foo, bar][sai, foo, bar, prasad]Number of items in the list:4