转换字符串数组为地图 [英] Converting string arrays into Map

查看:120
本文介绍了转换字符串数组为地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字符串数组键和值

I have two string arrays keys and values

String[] keys = {a,b,c,d};

String[] values = {1,2,3,4};

什么是将它们转换成图的最快方法?我知道我们可以遍历它们。但是,有没有实用present?

What is the fastest way to convert them into a map? I know we can iterate through them. But, is there any utility present?

推荐答案

比这个更快?

HashMap<String,String> map = new HashMap<String,String>();
if(keys.length == values.length){
    for(int index = 0; index < keys.length; index++){
        map.put(keys[index], values[index]);
    }
}

这篇关于转换字符串数组为地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆