Results 1 to 2 of 2
  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Rep Power

    Default Single Linked List boolean

    Hi i'm currently studying over single linkedLists and i'm just writing various methods for it. One method i'm currently stuck on is writing a remove method where it returns a boolean true if its found and it will delete it, and false if the target isn't found. My problem is that it always comes up as flase and i know that the target is in the linked list.
    Here is the code for my method.

    Java Code:
    public boolean remove(E item){
    Node<E> ptr = head;
    		while(ptr!= null && !item.equals(item))
    			ptr =;
    		if({ =;
    			return true;
    		return false;	
    And here is the some of code that is in my testing class
    Java Code:
    Node<String> California = new Node<String>("California");
    		Node<String> Florida = new Node<String>("Florida");
    		Node<String> Alabama = new Node<String>("Alabama");
    		Node<String> Kentucky = new Node<String>("Kentucky"); = Florida; = California; = Kentucky;

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Single Linked List boolean

    Do you really want to compare 'item' against itself in line #3?

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 0
    Last Post: 09-25-2012, 04:07 AM
  2. Replies: 4
    Last Post: 02-21-2011, 09:34 AM
  3. accessing single linked list from another class
    By el9335 in forum New To Java
    Replies: 4
    Last Post: 10-07-2010, 01:52 PM
  4. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  5. Single linked lists - help
    By Srcee in forum New To Java
    Replies: 10
    Last Post: 10-29-2009, 05:35 PM

Posting Permissions

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