工具类:
ToUpperCaseKeyMapUtil.java
public class ToUpperCaseKeyMapUtil {//对单一的mappublic static <T> Map<String, T> toUpperCaseKeyMap(Map<String, T> map) {if (map != null) {List<String> mapKeyList = new ArrayList<>(map.keySet());mapKeyList.forEach(key->{map.put(key.toUpperCase(),map.remove(key));//字段名转大写});}return map;}//对不唯一的map集合进行转换public static <T> List<Map<String, T>> toUpperCaseKeyMapList(List<Map<String, T>> mapList) {if (mapList != null && mapList.size() > 0) {mapList.forEach(ToUpperCaseKeyMapUtil::toUpperCaseKeyMap);}return mapList;}/*** key转小写** @param orgMap* @return*/public static Map<String, Object> keyToLowerCase(Map<String, Object> orgMap) {Map<String, Object> resultMap = new HashMap<>();if (orgMap == null || orgMap.isEmpty()) {return resultMap;}Set<Map.Entry<String,Object>> entrySet = orgMap.entrySet();for (Map.Entry<String, Object> entry : entrySet) {String key = entry.getKey();Object value = entry.getValue();resultMap.put(key.toLowerCase(), value);}return resultMap;}}
使用:
public static void main(String[] args) {HashMap<String, Object> map = new HashMap<>();map.put("ksd","999");map.put("ads","999");HashMap<String, Object> map1 = new HashMap<>();map1.put("ew","23123");Map<String, Object> upperCaseKeyMap = toUpperCaseKeyMap(map);Set<String> strings = upperCaseKeyMap.keySet();System.out.println(strings);System.out.println("===========================================");List<Map<String,Object>> list = new ArrayList<>();list.add(map);list.add(map1);List<Map<String, Object>> mapList = toUpperCaseKeyMapList(list);mapList.stream().forEach(stringObjectMap -> System.out.println(stringObjectMap));}