package com.soar.list;
import java.util.LinkedList;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class Demo3_LinkedList {
/*
* * A:LinkedList类概述
* B:LinkedList类特有功能
* public void addFirst(E e)及addLast(E e)
* public E getFirst()及getLast()
* public E removeFirst()及public E removeLast()
* public E get(int index);
*/
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.addFirst("a"); //在头处添加
list.addFirst("b");
list.addFirst("c");
list.addFirst("d");
//System.out.println(list); //[d, c, b, a]
list.addLast("e"); //在尾处添加
System.out.println(list); //[d, c, b, a, e]
//System.out.println(list.getFirst()); //d
//System.out.println(list.getLast()); //e
//System.out.println(list.removeFirst()); //d
//System.out.println(list.removeLast()); //e
//System.out.println(list); //[c, b, a]
System.out.println(list.get(1)); //c
System.out.println(list); //[d, c, b, a, e]
}
}
Java_基础—LinkedList的特有功能
最新推荐文章于 2022-03-07 17:21:36 发布