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

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

Description

to Map

License

Apache License

Declaration

public static final <K, V> Map<K, V> toMap(Object... objects) 

Method Source Code

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

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

public class Main {
    public static final <K, V> Map<K, V> toMap(Object... objects) {
        if (objects == null || objects.length % 2 != 0)
            throw new IllegalArgumentException(
                    "Illegal arguments provided to construct a map");
        Map<K, V> ret = new HashMap<K, V>();
        for (int i = 0; i < objects.length; i += 2) {
            ret.put((K) objects[i], (V) objects[i + 1]);
        }/*from w w w  .j a  v a2s.  c o  m*/
        return ret;
    }
}

Related

  1. map(T... input)
  2. toMap(Object... args)
  3. toMap(Object... args)
  4. toMap(Object... data)
  5. toMap(Object... objects)
  6. toMap(Object... pairs)
  7. toMap(Object... pairs)
  8. toMap(Object[] array)
  9. toMap(Object[] array)