Java Map Create createMapFromArgs(Object... args)

Here you can find the source of createMapFromArgs(Object... args)

Description

create Map From Args

License

Open Source License

Declaration

public static Map<String, Object> createMapFromArgs(Object... args) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<String, Object> createMapFromArgs(Object... args) {
        Map<String, Object> result = new HashMap<String, Object>();

        if (args.length % 2 != 0)
            throw new IllegalArgumentException("There must be a pair number of arguments");

        for (int i = 0; i < args.length; i = i + 2) {
            String keyArg = (String) args[i];
            Object arg = args[i + 1];
            result.put(keyArg, arg);/*  w ww .j  a v a  2 s  .c  om*/
        }

        return result;
    }
}

Related

  1. createMap(String[] mappings, String sep)
  2. createMap(T... _args)
  3. createMap(U... items)
  4. createMap_pollutantHourly()
  5. createMapFor(String... args)
  6. createMapFromProperties(Properties stringSubstitutionVariables)
  7. createMapFromWebsiteList(String[] websiteList)
  8. map(final Entry... entries)
  9. map(final Object... keysAndValues)