class Node {
String data = null; //链表存储的数据
Node next = null; //下一个节点
public Node (String data) {
this.data = data;
}
public void setNext(Node next) {
this.next = next;
}
public Node getNext() {
return next;
}
public String getData() {
return data;
}
}
遍历链表
public static void getDataByLoop(Node node){
while (node != null) {
System.out.println(node.getData());
node = node.getNext();
}
}