Converting string arrays into Map

前端 未结 5 628
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 13:46

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 i

5条回答
  •  醉酒成梦
    2020-11-29 14:15

    Faster than this?

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

提交回复
热议问题