zoukankan      html  css  js  c++  java
  • java学习笔记 LinkedList

    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.remove());
    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(a3); 
    42                
    43         
    44           
    45     }
    46 }
    47 
    48 /*
    49 public void addFirst(E e)
    50 public void addLast(E e)
    51 public boolean offer(E e)
    52 public E removeFirst()
    53 public E removeLast()
    54 public E element()
    55 public E peek()
    56 public E poll()
    57 public E remove()
    58 
    59 for(int i = 0;i < (a3.size()+ 2);i++) {
    60   System.out.print(a3.poll() + " ");
    61     System.out.println("执行第" + i + "次" + a3);    
    62 }
    63 
    64 1.public boolean offer()与public void addLast()除了返回值不同还有别的什么不同之处么?
    65 */

  • 相关阅读:
    如何做一名技术管理者
    图表控件amCharts
    Redis
    关于微信,我想说两句
    颜色名称集合
    【翻译】PSV初音Miku Project DIVAf
    【3DS】初音Miku and Future Stars Project
    处女作真人语音计算器上线了
    【PSV】GRAVITY DAZE(重力眩晕)
    看得我老泪横流,自己有多久没有像小女孩这样被惊喜过了?
  • 原文地址:https://www.cnblogs.com/yhwsy/p/5719099.html
Copyright © 2011-2022 走看看