使用treemap 遍历map参数

遍历格式 XXX=123&XXX=456.....参数为map

treemap是一个有序的key-value集合,它是通过红黑树实现的

TreeMap treeMap = new TreeMap<>();
        for (Map.Entry entry : map.entrySet()) {
            if ("signature".equals(entry.getKey().trim())) {
                continue;
            }
            if (StringUtils.isBlank(entry.getValue())) {
                continue;
            }
            treeMap.put(entry.getKey(), entry.getValue());
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry entry : treeMap.entrySet()) {
            stringBuilder.append(entry.getKey());
            stringBuilder.append("=");
            stringBuilder.append(entry.getValue());
            stringBuilder.append("&");
        }
        String result = "";
        if (StringUtils.isNotBlank(stringBuilder.toString())) {
            result = stringBuilder.substring(0, stringBuilder.length() - 1);
        }
        return result;
    }

 

转载于:https://www.cnblogs.com/wirr/p/8397659.html

你可能感兴趣的:(使用treemap 遍历map参数)