LinkedLiset的底层是以链表存储
LinkedList部分方法示例:
1 import java.util.LinkedList; 2 3 public class Test { 4 public static void main(String[] args) { 5 LinkedList a1 = new LinkedList(); 6 LinkedList a3 = new LinkedList(); 7 8 a1.add("A");a1.add(1,"B");a1.add("C"); 9 a1.addFirst("first");a1.addLast("last"); 10 11 System.out.println(a1.offer("last")); 12 System.out.println(a1); 13 14 a1.removeFirst();a1.removeLast(); 15 System.out.println(a1.removeLast()); 16 System.out.println(a1); 17 18 LinkedList a2 = new LinkedList(a1); 19 System.out.println("+++++++++++++++++++++++++++++++++++++++++++"); 20 System.out.println(a2); 21 22 23 24 25 System.out.println("找到链表的表头element" + " " + a2.element()); 26 System.out.println("a2内容:" + " "+a2); 27 System.out.println("找到但不删除链表的头peek" + " " + a2.peek()); 28 System.out.println("a2内容:" + " "+a2); 29 30 System.out.println( "检索并移除表头remove" + " " + a2.peek()); 31 System.out.println("a2内容:" + " "+a2); 32 System.out.println("找到并删除此链表的头poll" + " " + a2.poll()); 33 System.out.println("a2内容:" + " "+a2); 34 35 a3.add("A");a3.add("B");a3.add("C"); 36 int j = a3.size(); 37 for(int i = 0;i < j;i++) { 38 System.out.print(a3.poll() + " "); 39 System.out.println("执行第" + i + "次" + a3); 40 } 41 System.out.println(" "); 42 System.out.println(a3); 43 44 45 46 } 47 } 48 49 /* 50 public void addFirst(E e) 51 public void addLast(E e) 52 public boolean offer(E e) 53 public E removeFirst() 54 public E removeLast() 55 public E element() 56 public E peek() 57 public E poll() 58 public E remove() 59 60 for(int i = 0;i < (a3.size()+ 2);i++) { 61 System.out.print(a3.poll() + " "); 62 System.out.println("执行第" + i + "次" + a3); 63 } 64 65 1.public boolean offer()与public void addLast()除了返回值不同还有别的什么不同之处么? 66 */
原文:http://www.cnblogs.com/yhwsy/p/5719099.html