Java tutorial
//package com.java2s; //License from project: Apache License import java.util.LinkedHashMap; import java.util.Map; public class Main { @SuppressWarnings("unchecked") public static <T> Map<T, Object> asMap(T key, Object... values) { if ((values == null || values.length == 0) && key instanceof Map) { return (Map<T, Object>) key; } Map<T, Object> result = new LinkedHashMap<>(); if (values == null) { result.put(key, null); return result; } if (values.length % 2 == 0) { throw new IllegalArgumentException("value[] must be not null and an odd length"); } result.put(key, values[0]); for (int i = 1; i < values.length; i += 2) { result.put((T) values[i], values[i + 1]); } return result; } }