LinkedList类扩展AbstractSequentialList并实现List接口。它提供了一个链表数据结构。
从它的父类继承的方法
除了,链表定义下面的方法:
空隙加载(INT指数,对象元素)在 插入指定的元素在此列表中的指定位置的索引。抛出 IndexOutOfBoundsException异常如果指定的索引是超出范围 (索引< 0 ||指数>尺寸())。
空隙addfirst仅(对象O)插入在 该列表开始处的给定的元件。
空隙addlast仅(对象o)将给定元素追加到此 列表
对象获取(INT指数)的端部在此 列表中指定位置返回元素。抛出IndexOutOfBoundsException异常如果指定的索引是 超出范围(索引< 0 ||指数> =尺寸())。
我会告诉你的示例代码。此五月帮助你,
import java.util.*;
public class LinkedListDemo{ public static void main(String args[])
{// create a linked list
LinkedList ll =new LinkedList();// add elements to the linked list
ll.add("F");
ll.add("B");
ll.add("D");
ll.add("E");
ll.add("C");
ll.addLast("Z");
ll.addFirst("A");
ll.add(1,"A2");
System.out.println("Original contents of ll: "+ ll);// remove elements from the linked list
ll.remove("F");
ll.remove(2);
System.out.println("Contents of ll after deletion: "+ ll);// remove first and last elements
ll.removeFirst();
ll.removeLast();
System.out.println("ll after deleting first and last: "+ ll);// get and set a valueObject val = ll.get(2);
ll.set(2,(String) val +" Changed");
System.out.println("ll after change: "+ ll);
}
}
如果您怀疑链表,请搜索关于数据结构上java..thank你 ..Vote我背部。!
使用正确的格式。代码。 – Sandeep