标签:
1. LinkedList的特有功能:
(1)添加功能
public void addFirst(Object e)
public void addLast(Object e)
(2)获取功能
public Object getFirst()
public Obejct getLast()
(3)删除功能
public Object removeFirst()
public Object removeLast()
2. 代码示例:
1 package cn.itcast_03; 2 3 import java.util.LinkedList; 4 5 /* 6 * LinkedList的特有功能: 7 * A:添加功能 8 * public void addFirst(Object e) 9 * public void addLast(Object e) 10 * B:获取功能 11 * public Object getFirst() 12 * public Obejct getLast() 13 * C:删除功能 14 * public Object removeFirst() 15 * public Object removeLast() 16 */ 17 public class LinkedListDemo { 18 public static void main(String[] args) { 19 // 创建集合对象 20 LinkedList link = new LinkedList(); 21 22 // 添加元素 23 link.add("hello"); 24 link.add("world"); 25 link.add("java"); 26 27 // public void addFirst(Object e) 28 // link.addFirst("javaee"); 29 // public void addLast(Object e) 30 // link.addLast("android"); 31 32 // public Object getFirst() 33 // System.out.println("getFirst:" + link.getFirst()); 34 // public Obejct getLast() 35 // System.out.println("getLast:" + link.getLast()); 36 37 // public Object removeFirst() 38 System.out.println("removeFirst:" + link.removeFirst()); 39 // public Object removeLast() 40 System.out.println("removeLast:" + link.removeLast()); 41 42 // 输出对象名 43 System.out.println("link:" + link); 44 } 45 }
运行效果如下:
Java基础知识强化之集合框架笔记26:LinkedList的特有功能
标签:
原文地址:http://www.cnblogs.com/hebao0514/p/4855399.html