Here you can find the source of sort(Map
public static Map<String, Object> sort(Map<String, Object> src)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Main { public static Map<String, Object> sort(Map<String, Object> src) { Map<String, Object> result = new LinkedHashMap<String, Object>(); List<String> keys = new ArrayList<>(src.keySet()); Collections.sort(keys);//from w w w . j a v a 2 s . co m for (String key : keys) { result.put(key, src.get(key)); } return result; } }