Java sorting LinkedList with Map.Entry objects
Go to solution
Solved by Mr_KoKa,
LinkedList<Map.Entry> entryList = new LinkedList(); //YourlistCollections.sort(list, new Comparator<Map.Entry>() { @[member='OverRide'] public int compare(Map.Entry e1, Map.Entry e2) { return //Helper function goes here, or just split it into if and many returns. }});Your return value needs to be either a negative integer, zero, or a positive integer as the first argument (e1) is less than, equal to, or greater than the second (e2).
You can make yourself a helper function that will compare two entries and return integer so you can use it inline with return like, return yourCompareFunction(e1, e2);
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now