Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 723
user2434 Avatar asked Sep 14 '12 04:09

user2434


1 Answers

Faster than this?

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]);
    }
}
like image 98
Sujay Avatar answered Nov 15 '22 06:11

Sujay