I am having a scenario where I have a list of objects say List<Vehicle>
. Each of the Vehicle
object has a list of another object say Group
. So the Vehicle
object has a property called groups
which is a List<Groups>
.
Basically, the structure is like this :
public class Vehicle {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer wuid;
private String description;
@ManyToMany
@JoinTable(
name="wuclassification"
, joinColumns={
@JoinColumn(name="wuid")
}
, inverseJoinColumns={
@JoinColumn(name="classid")
}
)
private List<Group> groups;
}
And the Group class is like :
public class Group {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer groupId;
private String name;
}
So now I have a list of Vehicle
objects with its list of Group
objects. Is there a way of sorting the work unit objects based on the list of group objects with their name attribute?
For example, say I have a list of Vehicle
objects which has a Bike, Car and Truck.
And then the list of groups with their names for this vehicles are :
Bike : ['short distance','bike taxi']
Car : ['goods career','long distance','short distance','taxi']
Truck : ['goods carrier','long distance']
So sorting this based on the list of groups should look like :
Truck : ['goods carrier','long distance']
Car : ['goods career','long distance','short distance','taxi']
Bike : ['short distance','bike taxi']
I followed this link of sorting List<List> from this link : Java Sort List of Lists
But I am not able apply a similar approach in this scenario. How can I can implement the sorting? Would gladly appreciate your help and thanks in advance.