本帖最后由 Kevin.Kang 于 2015-7-17 14:42 编辑
- package com.kxg_LinkidList;
- import java.util.LinkedList;
- /*
- * LinkedList类特有功能:
- * 1:添加功能
- * public void addFirst(Object obj)
- * public void addLast(Object obj)
- * 2:获取功能
- * public Object getFirst()
- * public Object getLast()
- * 3:删除功能
- * public Object removeFirst()
- * public Object removeLast()
- */
- public class LinkedListDemo {
- public static void main(String[] args) {
- // 定义集合
- LinkedList<String> list = new LinkedList<>();
- // 添加元素
- list.add("java");
- // public void addFirst(Object obj)
- list.addFirst("javase");
- System.out.println(list);
- // public void addLast(Object obj)
- list.addLast("android");
- System.out.println(list);
- // public Object getFirst()
- System.out.println(list.getFirst());
- // public Object getLast()
- System.out.println(list.getLast());
- // public Object removeFirst()
- System.out.println(list.removeFirst());
- System.out.println(list);
- // public Object removeLast()
- System.out.println(list.removeLast());
- System.out.println(list);
- }
- }
复制代码
|
|