我是靠谱客的博主 美丽洋葱,这篇文章主要介绍把键值添加至Map,现在分享给大家,希望可以做个参考。

/**

     * 把键值添加至Map<br/>

     * pair:name=value

     * @param pair name=value

     * @param m

     */

    public static void putMapByPair(String pair, Map m) {

        if(null == pair || "".equals(pair)) {

            return;

        }

        int indexOf = pair.indexOf("=");

        if(-1 != indexOf) {

            String k = pair.substring(0, indexOf);

            String v = pair.substring(indexOf+1, pair.length());

            if(null != k && !"".equals(k)) {

                m.put(k, v);

            }

        } else {

            m.put(pair, "");

        }

    }

 

    public static void main(String[] args) {

        Map map=new HashMap();

        map.put("44", "bbb");

        System.out.println(map);

        putMapByPair("aaa=222", map);

        System.out.println(map);

打印结果:

//{44=bbb}

//{aaa=222, 44=bbb}

    }

最后

以上就是美丽洋葱最近收集整理的关于把键值添加至Map的全部内容,更多相关把键值添加至Map内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部