// We'll use instances of this object in main() below. class ListItem { String data; ListItem next; } public class StrangeExample4 { static ListItem first = null; static ListItem last = null; public static void main (String[] argv) { // Make one instance and put a string in the data field. first = new ListItem(); first.data = "Yes minister"; last = first; // Add the rest. add ("Seinfeld"); add ("Cheers"); add ("Frasier"); add ("Simpsons"); // Now print by repeatedly advancing the pointer - in a simple loop. ListItem listPointer = first; while (listPointer != null) { System.out.println (listPointer.data); listPointer = listPointer.next; } } static void add (String s) { // Make a new instance (new list node) and add the data. ListItem nextOne = new ListItem(); nextOne.data = s; // Make the current last one point to the new one. last.next = nextOne; // Adjust the last pointer. last = nextOne; } }