Java Map from Array toMap(Object... args)

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

Description

to Map

License

Open Source License

Declaration

public static Map<String, Object> toMap(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> toMap(Object... args) {
        if (args.length % 2 == 1)
            throw new RuntimeException("toMap must be called with an even number of parameters");
        HashMap<String, Object> map = new HashMap<String, Object>();
        for (int i = 0; i < args.length; i += 2) {
            String key = "" + args[i];
            Object value = args[i + 1];
            map.put(key, value);//from  www. j  a  va 2 s . c o  m
        }
        return map;
    }
}

Related

  1. map(String... keyValues)
  2. map(String... strings)
  3. map(String... vals)
  4. map(T... input)
  5. toMap(Object... args)
  6. toMap(Object... data)
  7. toMap(Object... objects)
  8. toMap(Object... objects)
  9. toMap(Object... pairs)