Results 1 to 2 of 2
  1. #1
    ohiopotato is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default Someone help me with this method?

    I've written a method to fetch a node from a linked list, but it returns null for a unsuccessful search even when I know that the node exists. coudl anyone help me out with this?

    public T fetch(String incoming)
    {
    Key previous;
    Key here = (Key) head;
    Key toSend = null;
    for(int i = 1; i <= this.size; i++)
    {
    previous = here;
    here = previous.getNext();
    if(incoming.equals(here.getName()))
    {
    toSend = here;
    }

    }
    return (T) toSend;
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Debug it, or println() it, to see what values all those things hold.
    That is incoming, here, previous, here.name.

Similar Threads

  1. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  2. Turning Recursion Method into Iterative method
    By mattakuevan in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 06:46 AM
  3. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  4. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 07:20 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •