Hi, I am trying create a linked list to store some data. How can I retrieve the actual data from the list values and not the item's object reference.
public class myList()
{
private LinkedList<Node> list = null;
public myList()
{
list = new LinkedList<Node>();
}
public void addX(Node x)
{
list.add(x)
}
public void print()
{
for(int i = 0; i<list.size(); i++)
{
System.out.println(list.get(i));
}
}
}
public class Node
{
private String x;
private int y;
private int z;
public Node(String x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
public static void main (String[] args)
{
myList.addX(new Node(x,1,2));
myList.print();
}
When I run this it prints the memory address/reference instead of the actual values. What am I doing wrong? Example output: Node@838378c7
Any help is appreciated.
Thanks.