Java LinkedList基礎篇

來源:互聯網
上載者:User

標籤:util   nbsp   ext   doc   java   pop   tle   設定   end   

好久沒用LinkedList,發現好多基礎的東西都不會了,所以特別寫這篇來總結一下關於LinkedList的基本用法。

java.util

class LinkedList<E>

建構函式:

  1.  public LinkedList(); 建立一個空的鏈表。
  2.  public LinkedList(Collection<? extends E> c); 按照已有集合的順序來構造鏈表。

常用方法:

  1.  public E getFirst();  返回鏈表的第一個元素。
  2.  public E getLast();     返回鏈表的最後一個元素。
  3.  public void addFirst(E e);  在鏈表的開頭插入指定的元素。
  4.  public void addLast(E e);  在鏈表的結尾插入指定的元素。
  5.  public boolean add(E e);   在鏈表的結尾插入指定的元素,等同於addLast方法。          
  6.  public boolean add(int index, E e);     在鏈表的指定位置插入指定的元素。
  7.  public E pop();    出棧。
  8.  public E push(E e);       壓棧。
  9.  public E remove();                  刪除鏈表的第一個元素。
  10.  public E remove(int index);     刪除鏈表指定位置的元素。 
  11.  public E removeFirst();           刪除鏈表的第一個元素。
  12.  public E removeLast();           刪除鏈表的最後一個元素。
  13.  public void clear();          刪除鏈表中的所有元素。
  14.  public E get(int index);    擷取鏈表指定位置的元素。
  15.  public void set(E e);        設定鏈表指定位置的元素。
  16.  public int size();               返回鏈表元素的個數。

詳細方法可參考API: http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html#size() 

Java LinkedList基礎篇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.