• 将map中的key全部转化为大写或者小写


    package com.alphajuns.mapTest;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;
    
    /**
     * @ClassName MapTest
     * @Description map键转换
     * @Author AlphaJunS
     * @Date 2020/11/11 21:24
     * @Version 1.0
     */
    public class MapTest {
    
        public static void main(String[] args) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("NAME", "张三");
            map.put("AGE", "24");
            map.put("ADDRESS", "广州");
            Map<String, String> lowerKeyMap = toLowerKey(map);
            System.out.println(lowerKeyMap);
            Map<String, String> map1 = new HashMap<String, String>();
            map1.put("name", "李四");
            map1.put("age", "25");
            map1.put("address", "深圳");
            Map<String, String> upperKeyMap = toUpperKey(map1);
            System.out.println(upperKeyMap);
        }
    
        /**
         * @Author AlphaJunS
         * @Date 21:50 2020/11/11
         * @Description 将map中的所有key转化为小写
         * @param map
         * @return java.util.Map<java.lang.String,java.lang.String>
         */
        public static Map<String, String> toLowerKey(Map<String, String> map) {
            Map<String, String> resultMap = new HashMap<String, String>();
            Set<String> sets = map.keySet();
            for (String key : sets) {
                resultMap.put(key.toLowerCase(), map.get(key));
            }
            return resultMap;
        }
    
        /**
         * @Author AlphaJunS
         * @Date 21:51 2020/11/11
         * @Description 将map中的所有key转化为大写
         * @param map
         * @return java.util.Map<java.lang.String,java.lang.String>
         */
        public static Map<String, String> toUpperKey(Map<String, String> map) {
            Map<String, String> resultMap = new HashMap<String, String>();
            Set<String> sets = map.keySet();
            for (String key : sets) {
                resultMap.put(key.toUpperCase(), map.get(key));
            }
            return resultMap;
        }
    
    }
  • 相关阅读:
    java project 和 java web project 获取路径问题
    java.lang.UnsupportedClassVersionError: *** : Unsupported major.minor version 51.0
    Hibernate Annotation (Hibernate 注解)
    远程访问(post 传参数) 以及IOUtils复制文件
    使用jdk中keytool生成证书
    Chrome 的滚动条修改.
    https原理及tomcat配置https方法
    HttpClient 访问 https 出现peer can't
    Dom4j解析xml
    Tomcat Server 配置
  • 原文地址:https://www.cnblogs.com/alphajuns/p/13961238.html
Copyright © 2020-2023  润新知