Java Map Add arrayAsMap(Object... t)

Here you can find the source of arrayAsMap(Object... t)

Description

array As Map

License

Apache License

Declaration

public static Map<String, Object> arrayAsMap(Object... t) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;

import java.util.Map;

public class Main {

    public static Map<String, Object> arrayAsMap(Object... t) {
        if (t == null || t.length <= 0) {
            return null;
        }//  w  w w. ja  v  a2s  .co m
        if (t.length % 2 != 0) {
            throw new RuntimeException("illegal args count");
        }
        Map<String, Object> params = new HashMap<String, Object>(t.length);
        for (int i = 0; i < t.length; i += 2) {
            if (t[i] == null || !t[i].getClass().equals(String.class)) {
                throw new RuntimeException("illegal arg: " + t[i] + "at " + i);
            }
            String key = t[i].toString();
            Object value = t[i + 1];
            params.put(key, value);
        }
        return params;
    }
}

Related

  1. addToMapIfNotNull(Map map, String key, Object value)
  2. addToMapListUnique(Map> mapList, T key, List values)
  3. addToMapMap(Map> map, K1 key1, K2 key2, V value)
  4. addToMapMap(Map> map, T key, V val)
  5. addToMapOfLists(Map> map, S key, T value)
  6. arrayToMap(int[] array)
  7. arrayToMap(Map destMap, Object[]... oaaArray)
  8. ArrayToMap(Object[] a)
  9. arrayToMap(Object[] array)