Ich möchte nur meine HashMap nach Schlüssel sortieren und brauche bitte Hilfe. Was ich habe, so weit:Wie sortiere ich HashMap von TreeMap in Java
Map<String, Map<String, String>> unsortedMapResult = new HashMap<String, Map<String, String>>();
unsortedMapResult.put("Delete Items", "Before items", "After items");
unsortedMapResult.put("Audit Items", "Before items", "After items");
Map<String, Map<String, String>> treeMapResult = new TreeMap<String,
Map<String, String>>(unsortedMapResult);
Map<String, Map<String, String>> finalResult = new HashMap<String, Map<String, String>>();
ich einfach die TreeMap gehe und kopieren Sie Inhalte auf eine neue HashMap
Set<Entry<String, Map<String, String>>> entrySets = treeMapResult.entrySet();
for (Entry<String, Map<String, String>> ent : entrySets) {
finalResult.put(ent.getKey(), ent.getValue());
}
return finalResult;
Das Problem ist finalResult jetzt nicht sortiert ist und ist genau das gleiche wie meine erste unsortedMapResult .
ich es haben möchte, so dass sie wie folgt sortiert:
Audit Items, Before items, After items
Delete Items, Before items, After items