[Solved] Java. Compare two objects values in LinkedList


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);

solved Java. Compare two objects values in LinkedList