0

I'm trying to print out the stored data of my LinkedList with toString method with the code below:

class Node {
    public Record poi;
    public Node next;

    public Node(Record poi) {
        this.poi = poi;
    }
}

class RankList {

    private Node first;
    private int nodeCount;
    private Record record;

    public static void main(String[] args) {
        RankList list = new RankList();
        Point point = new Point(5.4, 3.2);
        Record record = new Record(1, point, 8.2);
        System.out.println(list.insert(record));
        System.out.println(list.toString);
    }

 @Override
 public String toString() {
    return String.format("Node(%d,)", id); //...
 }

I'm trying to show something like that and to see that the data is stored correctly.

Node 1=> Id:1 Score:8.2 Point: 5.4,3.2
Node 2=> ...

But the thing I get as a result is the following:

Node@7a79be86
Michael Pnrs
  • 115
  • 11
  • 1
    Does this answer your question? [How do I print my Java object without getting "SomeType@2f92e0f4"?](https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4) – OH GOD SPIDERS Nov 17 '20 at 15:59
  • 1
    You have only overriden the toString method of your RankList class, but not your Node class. So you havent told java how it should print your Node class and it will just use the default implementation – OH GOD SPIDERS Nov 17 '20 at 16:00

1 Answers1

1

Your toString is in the RankList class. You should implement it also in Node class

Steve H.
  • 6,912
  • 2
  • 30
  • 49