user2434 user2434 -4 years ago 242
Java Question

Converting string arrays into 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?

Answer Source

Faster than this?

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]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download