'How to Sort an element in an inner HashMap in a nested Hashmap?
My goal is to replace the relevant HashMap with an appropriate Collection to get the Output entries sorted by last name.
Is there any method that can get the Output entries sorted by lastname?
I don't have an error, but I will be really thankful if I can understand how such a thing can be done.
Ps : I did implement method that convert the HashMap to ArrayList but i after that I reach somehow a dead end.
public class PhoneBook {
String firstname;
String lastname;
String number;
HashMap<HashMap<String, String>, String> nestedMap = new HashMap<>();
//Constructor for the contacts
public PhoneBook(String firstname , String lastname, String number) {
this.firstname=firstname;
this.lastname=lastname;
this.number=number;
HashMap<String, String> valueMap = new HashMap<String, String>();
valueMap.put(firstname, lastname) ;
this.nestedMap.put( valueMap, number);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
