你也可以访问这个地址继续学习:https://www.processon.com/view/6076a7ffe401fd2d66980f5b
更多技术学习请到:https://www.processon.com/view/60504b5ff346fb348a93b4fa
1、转换前数据截图:
2、转换成功截图:
3、废话不多说,直接上代码
// main方法运行测试
public static void main(String[] args) {
Map<String, Object> m3 = new HashMap<String, Object>();
m3.put("a", "abc");
m3.put("b", "123");
m3.put("C", "123");
m3.put("dD", "123");
Map<String, Object> m4 = new HashMap<String, Object>();
m4.put("b", "123");
m4.put("a", "abc");
m4.put("cDs", "123");
m4.put("d", "123");
System.out.println("将m4数据的key全部转换为大写===" + transformUpperCase(m4));
System.out.println("将m3数据的key全部转换为小写===" + transformLowerCase(m4));
}
// 将map值全部转换为大写
public static Map<String, Object> transformUpperCase(Map<String, Object> orgMap) {
Map<String, Object> resultMap = new HashMap<>();
if (orgMap == null || orgMap.isEmpty()) {
return resultMap;
}
Set<String> keySet = orgMap.keySet();
for (String key : keySet) {
String newKey = key.toUpperCase();
// newKey = newKey.replace("_", "");
resultMap.put(newKey, orgMap.get(key));
}
return resultMap;
}
// 将map值全部转换为小写
public static Map<String, Object> transformLowerCase(Map<String, Object> orgMap) {
Map<String, Object> resultMap = new HashMap<>();
if (orgMap == null || orgMap.isEmpty()) {
return resultMap;
}
Set<String> keySet = orgMap.keySet();
for (String key : keySet) {
String newKey = key.toLowerCase();
// newKey = newKey.replace("_", "");
resultMap.put(newKey, orgMap.get(key));
}
return resultMap;
}
转载注明出处:https://blog.csdn.net/qq_28245087/article/details/86652602