[Solved] Java. Compare two objects values in LinkedList

[ad_1]

First, add implements Comparable<Student> to class header and compareTo() method to Student class:

@Override
public int compareTo(Student other) {
    return Integer.valueOf(this.indexnr).compareTo(other.indexnr);
}

Then, sort your list:

List<Student> list3 = ...; //some logic to fill list
Collections.sort(list3);

[ad_2]

solved Java. Compare two objects values in LinkedList