1、
package com.shengsiyuan;
import java.util.LinkedList;
public class LinkedListTest1
{
public static void main(String[] args)
{
LinkedList list = new LinkedList();
list.add("F");
list.add("B");
list.add("D");
list.add("E");
list.add("C");
list.addLast("Z");
list.addFirst("A");
list.add(1, "A2");
System.out.println("最初的集合:" + list);
list.remove("F");
list.remove(2);
System.out.println("变化后的集合:" + list);
Object value = list.get(2);
list.set(2, (String)value + "changed");
System.out.println("最后的集合:" + list);
}
}
2、
package com.shengsiyuan;
public class Node
{
String date;
Node next;
public Node(String date)
{
this.date = date;
}
}
package com.shengsiyuan;
public class NodeTest
{
public static void main(String[] args)
{
Node node1 = new Node("node1");
Node node2 = new Node("node2");
Node node3 = new Node("node3");
node1.next = node2;
node2.next = node3;
System.out.println(node1.next.next.date);
System.out.println("-------------------");
Node node4 = new Node("node4");
node1.next = node4;
node4.next = node2;
System.out.println(node1.next.next.next.date);
node1.next = node2;
node4.next = null;
System.out.println(node1.next.next.date);
}
}