Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:36:09+00:00 2026-06-15T13:36:09+00:00

Been searching for a solution to my problem. Been reading a lot about overriding

  • 0

Been searching for a solution to my problem. Been reading a lot about overriding equals to properly compare nodes of a linked list but have become stuck. Basically I am trying to search through my list and find a node that equals it and delete it. I have found the way to look through the linked list but when I return the node it is just gibberish. I am trying to find a way to get it into a string and compare it to another string. Anyway here is the code and my equals method that currently does not work.

public class MagazineList {
    private MagazineNode list;
    private Object obj;

    public MagazineList(){
        list = null;
    }


    public void add(Magazine mag){
        MagazineNode node = new MagazineNode(mag);
        MagazineNode current;

        if(list==null)
            list = node;
        else{
            current = list;
            while(current.next != null)
                current = current.next;
            current.next = node;
        }   
    }
    public void insert(Magazine mag)
    {
        MagazineNode node = new MagazineNode (mag);

        // make the new first node point to the current root
        node.next=list;

        // update the root to the new first node
        list=node;
    }
    public void deleteAll(){
        if(list == null){

        }
        else{
            list = null;
        }
    }

    public void delete (Magazine mag) {
        MagazineNode current = this.list;
        MagazineNode before;

        //if is the first element
        if (current.equals(mag)) {
            this.list = current.next;
            return;     //ending the method
        }


        before = current;

        //while there are elements in the list
        while ((current = current.next) != null) {

            //if is the current element
            if (current.equals(mag)) {
                before.next = current.next;
                return;     //endind the method 
            }

            before = current;
        }

        //it isnt in the list
    }
    public boolean equals(Object other) {

        System.out.println("Here in equals" + other + this);
        // Not strictly necessary, but often a good optimization
        if (this == other)
            return true;
        else{
            return false;
        }
    }

    @ Override
    public String toString(){
        String result = " ";

        MagazineNode current = list;
        while (current != null){
            result += current.magazine + "\n";
            current = current.next;     
        }
        return result;
    }


    private class MagazineNode {
        public Magazine magazine;
        public MagazineNode next;


        public MagazineNode(Magazine mag){
            magazine = mag;
            next = null;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:36:10+00:00Added an answer on June 15, 2026 at 1:36 pm

    Your delete method looks fine, except you shouldn’t compare a MagazineNode with a Magazine. You should compare a Magazine with a Magazine.

    Replace if (current.equals(mag)) by if (current.magazine.equals(mag)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

been searching a lot information about IoC/DI development, but I haven't found much information
I've been searching for a solution for this problem but I couldn't solve it!
Hi I have been searching a solution to this problem for many days but
I have been searching for a solution to my problem but haven't found anything
I've been searching a lot for this problem and I can't find a solution.
I've been searching for a solution to this problem but been unable to find
Been searching all around but still cannot find a solution for this problem. My
I've been searching for hours for the solution to this problem but can't find
I've been searching through forums to find a solution for the problem I'm facing
I've been searching a solution for a while but couldn't find any. I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.