Java Map Create createMap(String key, Object value)

Here you can find the source of createMap(String key, Object value)

Description

create Map

License

Apache License

Declaration

static Map<String, Object> createMap(String key, Object value) 

Method Source Code


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

import java.util.HashMap;
import java.util.Map;

public class Main {
    static Map<String, Object> createMap(String key, Object value) {
        return createMap(new String[] { key }, new Object[] { value });
    }//from w w w.jav a  2s . c  o  m

    static Map<String, Object> createMap(String[] keys, Object[] values) {
        if (keys.length != values.length)
            throw new IllegalArgumentException("Keys and values must have same size.");
        Map<String, Object> map = new HashMap<String, Object>();
        for (int i = 0; i < keys.length; i++) {
            String key = keys[i];
            Object value = values[i];
            map.put(key, value);
        }
        return map;
    }
}

Related

  1. createMap(Object... args)
  2. createMap(Object... objects)
  3. createMap(Object... objects)
  4. createMap(Object[] keysValues)
  5. createMap(String entries)
  6. createMap(String[] list1, String[] list2)
  7. createMap(String[] mappings, String sep)
  8. createMap(T... _args)
  9. createMap(U... items)