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 7784159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:02+00:00 2026-06-01T20:03:02+00:00

I would really appreciate if you can help to answer to this question: I

  • 0

I would really appreciate if you can help to answer to this question:

I have already created a custom linked list myself in a very standard way using Java. Below are my classes:

public class Node {

   private Object obj;
   private Node next;

   public Node(Object obj){
       this(obj,null);
   }

   public Node(Object obj,Node n){
       this.obj = obj;
       next = n;
   }

   public void setData(Object obj){
       this.obj = obj;
   }

   public void setNext(Node n){
       next = n;
   }

   public Object getData(){
       return obj;
   }

   public Node getNext(){
       return next;
   }

}




public class linkedList {
    private Node head;


    public linkedList(){
        head = null;
    }

    public void setHead(Node n){
        head = n;
    }

    public Node getHead(){
        return head;
    }


   public void add(Object obj){
       if(getHead() == null){
           Node tmp = new Node(obj);
           tmp.setNext(getHead());
           setHead(tmp);
       }else{
           add(getHead(),obj);
       }
   }


   private void add(Node cur,Object obj){
       if(cur.getNext() == null){
           Node tmp = new Node(obj);
           tmp.setNext(cur.getNext());
           cur.setNext(tmp);
       }else{
           add(cur.getNext(),obj);
       }
   }


}

Im trying to print value i have inserted into the list as below

public static void main(String[] args) {
        // TODO code application logic here
        Node l = new Node("ant");
        Node rat = new Node("rat");
        Node bat = new Node("bat");
        Node hrs = new Node("hrs");

        linkedList lst = new linkedList();
        lst.add(l);
        lst.add(rat);
        lst.add(bat);
        lst.add(hrs);



        Node tmp = lst.getHead();
        while(tmp != null){

            System.out.println(tmp.getData());
            tmp = tmp.getNext();

        }


    }

but the output i got from the IDE is

linklist.Node@137bd6a1
linklist.Node@2747ee05
linklist.Node@635b9e68
linklist.Node@13fcf0ce

why does it print out the reference but not the actual value of the string such as bat,ant,rat… ?

If i want to print out the actual value then what should i do?

Thank you very much

  • 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-01T20:03:02+00:00Added an answer on June 1, 2026 at 8:03 pm

    Your linkedList class already creates the Nodes for you!

    linkedList list = new linkedList();
    list.add("foo");
    list.add("bar");
    Node tmp = lst.getHead();
    while(tmp != null){
        System.out.println(tmp.getData());
        tmp = tmp.getNext();
    }
    

    Will print

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

Sidebar

Related Questions

I would really appreciate if you could shed light on this problem. I have
Note - I will really appreciate a quick and complete answer to this question.
I would really appreciate it if some of you could help optimize my tables,
I would really appreciate if you would take a look at this piece of
I would really appreciate any help with the following problem: I need to be
I'm very new to C++ and would really appreciate any and all help. I
I'd really appreciate some help with an SQL query across tables. I realise this
I have asked a question like this before, and the answer was great but
I apologise if this question has already been asked. I'm really new to Python
I have a question that's so simple I cannot believe I can't answer it

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.