I have list with the following structure:
Class Data {
String id;
String type;
String reference;
}
The reference here may or may not be null. I have the following set of data in a list:
[
{
id:"1",
type:"A",
reference:"3"
},
{
id:"2",
type:"B",
reference:null
},
{
id:"3",
type:"C",
reference:"1"
}
]
I want it be sorted based on reference - 1 references 3 and 3 references 1. Such items have to be grouped together as below:
[
{
id:"1",
type:"A",
reference:"3"
},
{
id:"3",
type:"C",
reference:"1"
},
{
id:"2",
type:"B",
reference:null
}
]