public class Demo2 { public static Node first; // reference to linked list of Node objects public static void main(String[] args) { // Create nodes with data Node help1 = new Node(); help1.item = "to"; Node help2 = new Node(); help2.item = "be"; Node help3 = new Node(); help3.item = "or"; // Chain the nodes together using "next" help1.next = help2; help2.next = help3; help3.next = null; // null marks the end of the list // Important: first must ALWAYS reference to the first elem in list first = help1; // Done !!! /* ---------------------------------------------- Find node containing "be" ---------------------------------------------- */ Node p; p = findNode( first, "be" ); if ( p != null ) System.out.println( "Found: " + p.item ); else System.out.println( "Not found: " + p.item ); p = findNode( first, "question" ); if ( p != null ) System.out.println( "Found: " + p.item ); else System.out.println( "Not found: question"); } public static Node findNode( Node f, String s ) { Node p = f; while ( p != null ) { // Visiting node p (p.item = data store in p) if ( p.item.equals(s) ) return p; p = p.next; // Advances p to next node } return null; } }