1 public class Node { 2 3 String date; 4 Node next; 5 6 public Node(String date) { 7 this.date=date; 8 } 9 }
这是定义Node类,下面定义NodeTest来实现:
1 public class NodeTest { 2 3 /** 4 * LinkedList 链表练习 5 */ 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 9 Node node1=new Node("node1"); 10 Node node2=new Node("node2"); 11 Node node3=new Node("node3"); 12 13 node1.next=node2; 14 node2.next=node3; 15 16 System.out.println(node1.next.next.date); 17 } 18 19 }