Disclaimer : I have already once posted such a question and it was marked duplicate. Please try and help me. I have gone through all previous methods on stackoverflow and none was of any help. All the methods mentioned to sort Map(Key,Values) didn't work in my case as I have one step further i.e. retrieving the attribute of the value. This time, I tried to go with full detail.
I've a Map (String,Object) in Java and I want to sort it using one of the attributes of the Object.
e.g. Suppose I have a class
class Entry
{
int id;
String name;
String address;
//Rest of the code
}
Now, I created a map
Map<String,Entry>
I want to sort the map by the attribute id of the class Entry (Entry.id)
Please help !
For example, I have three objects of Entry class
entry1 :
id=1
name="abc"
address="india"
entry2 :
id=2
name="xyz"
address="india"
entry3 :
id=3
name="pqr"
address="india"
Now, I have the Map initially as follows :
Key : Value
first: entry2
second: entry3
third : entry1
After sorting, it should be like
Key : Value
third : entry1
first: entry2
second: entry3