Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Linked list Schminked list help with Nodes Please

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Thanked 0 Times in 0 Posts

    Default Linked list Schminked list help with Nodes Please

    In my CS class we just started working with linked lists. The book goes into PAINFUL EXCRUCIATING LONG WINDED VOLUMINOUS detail about what a linked list is (which all could be summarized in a few sentences), spits out a couple code snippets and expects me to put it together. I'm having a really difficult time with it.

    I can't even create a node. From my main I created an instance of the following, and everything is fine until I try I get to tom.next = dick.

    I'm just missing something, it keeps saying type expected. Any Linked List guidance would be greatlyu appreciated.

    import java.util.*;
    public class SingleLinkedList<E>
        Node<String> tom = new Node<String>("Tom");
        Node<String> dick = new Node<String>("Dick");
        Node<String> harry = new Node<String>("Harry");
        tom.next = dick;       //This is throwing up
        dick.next = harry;     //and this line as well
        private static class Node<E>
                  //Data Fields
                  //Reference to the data
                  private E data;
                  //Reference to the next node
                  private Node<E> next;
                  //Creates new node with a null next field
                  private Node(E dataItem)
                      data = dataItem;
                      next = null;
                  //Creats a new node that references another node
                  private Node(E dataItem, Node<E> nodeRef)
                      data = dataItem;
                      next = nodeRef;

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Linked list Schminked list help with Nodes Please

    /This is throwing up
    What is the error message you get? Please copy and paste here the full text.

    Instead of trying to directly access a class variable, you should have a setNext method you call to make the change.

Similar Threads

  1. Linked List Help
    By BuhRock in forum Collections and Generics
    Replies: 3
    Last Post: September 26th, 2011, 08:43 AM
  2. linked list help
    By tjoney in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 3rd, 2011, 06:54 PM
  3. [SOLVED] Linked List Help
    By lieles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 4th, 2011, 10:32 PM
  4. Help with linked list
    By joecool594 in forum Collections and Generics
    Replies: 3
    Last Post: November 28th, 2010, 12:33 PM
  5. Recursive function based on Linked list
    By rosh72851 in forum Collections and Generics
    Replies: 1
    Last Post: March 9th, 2009, 06:23 PM