I have a json like below :
{
"Student": [
{
"name":"5",
"Roll No":12345,
"Subjects":[
{
"subjectCode":"Mat"
},
{
"subjectCode":"Sci"
}
]
}
]
}
I want to sort list of subjects within each student and then sorting student objects with roll no.Can it be done with java8 in single line.
I am using below code :
list.forEach(studentObj -> {
studentObj.getSubjects()
.sort(Comparator.nullsLast(Comparator.comparing(Subject:: getSubjectCode)));
});
then sorting the outside object
list.sort(Comparator.nullsLast(Comparator.comparing(Student:: getRollNo)));
Can it be done with java8 in single line?Yes probably, give it a try.