I have a list of maps like below. I want to sort the maps inside the list in custom order in Java 8.
For Example, Below is the list of maps .
[{model=Ferrari},
{model=Tesla},
{model=Benz},
{model=Honda}]
If I sort the above list of maps using the below code, Its sorting in Alphabetical order.
l.sort(Comparator.comparing((Map<String,String> mp) -> mp.get("model")));
gives the output below.
[{model=Benz}, {model=Ferrari}, {model=Honda}, {model=Tesla}]
But I need to sort this map based on the order(Not Alphabetical Order) : Honda,Tesla,Benz, Ferrari
Is there a better approach we can achieve the custom sort in Java 8 ?