将字符串数组转换为 Map [英] Converting string arrays into Map
本文介绍了将字符串数组转换为 Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串数组键和值
I have two string arrays keys and values
String[] keys = {a,b,c,d};
String[] values = {1,2,3,4};
将它们转换为地图的最快方法是什么?我知道我们可以遍历它们.但是,有任何实用程序吗?
What is the fastest way to convert them into a map? I know we can iterate through them. But, is there any utility present?
推荐答案
比这还快?
Map<String,String> map = new HashMap<>();
if(keys.length == values.length){
for(int index = 0; index < keys.length; index++){
map.put(keys[index], values[index]);
}
}
这篇关于将字符串数组转换为 Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文