I am using such linked list:

private Class Node
    public int Num1;
    public int Num2;

LinkedList<Node> list = new LnkedList<Node>();

Node n = new Node();
n.Num1 = 10;
n.Num2 = 100;

but now I don't know how to access Num1 and Num2 using my LinkedList. For example, I want to sort my linked list according to Num1 using Collections.sort(?) but I do not know how to specify that.

Edited by hg_fs2002

5 Years
Discussion Span
Last Post by corby

If you have a reference to a Node class object you can use that reference to access the public members of the Node class.
There are several versions of the sort() method. Use the one that takes a Comparator that you provide.


Node aRefToNode = new Node();

aRefToNode is a reference to an instance of a Node class object.

will access tthe num1 class member

Edited by NormR1


yes do what NormR1 saud. for any class you have, for example your Node class, you can acess the data members by placing a "." without quotations after your object or you could always use a get method to return the data depending if your data is private, protected, or public

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.