I have a Map that has strings for both keys and values.
Data is like following:
\"question1\", \"1\" \"question9\", \"1\" \"que
Using Java 8:
Map sortedMap = unsortMap.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));