Create Map out of string array in pair - Android java.lang

Android examples for java.lang:array

Description

Create Map out of string array in pair

Demo Code

import android.os.Build;
import java.util.HashMap;

public class Main{

    public static HashMap<String, String> getMap(String... strings) {
        if (strings.length % 2 != 0) {
            return null;
        }/*from   ww  w .j a  v a  2 s .  c om*/

        HashMap<String, String> params = new HashMap<String, String>();
        for (int i = 0; i < strings.length - 1; i += 2) {
            params.put(strings[i], strings[i + 1]);
        }

        return params;
    }

}

Related Tutorials