I have a list of MyObject
List<MyObject> myObjects;
where MyObject
is a model class something like below
public class MyObject{
private String fName;
private String lname;
private String code;
//getter setter
}
there are four possible value of code let's say ABC,DEF,XYZ and PQR
.
Now i want to sort the list based on following criteria. All object with code value XYZ
should come first, followed by PQR
,ABC
and DEF
.
- XYZ
- PQR
- ABC
- DEF
I want to achieve this using java 8 if possible. How can i sort my ArrayList.