zoukankan      html  css  js  c++  java
  • 将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;
        }
    
    }
  • 相关阅读:
    grab jpegs from v4l2 devices
    c helloworld on zynq
    minicom installation and configuration on ubuntu
    DBA的做法
    sqlserver锁表、解锁、查看销表
    linux内核分析(网课期末&地面课期中)
    Linux内核分析实验八------理解进程调度时机跟踪分析进程调度与
    LINUX内核分析第七周——可执行程序的装载
    Linux内核分析实验六
    Linux内核分析实验五
  • 原文地址:https://www.cnblogs.com/alphajuns/p/13961238.html
Copyright © 2011-2022 走看看