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

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

Description

to Map

License

Open Source License

Declaration

@SuppressWarnings({ "unchecked" })
    public static <K, V> Map<K, V> toMap(Object... data) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    @SuppressWarnings({ "unchecked" })
    public static <K, V> Map<K, V> toMap(Object... data) {
        if (data.length % 2 != 0) {
            throw new IllegalArgumentException("data length: "
                    + data.length);//from  w  w w . j  av  a2s  .  com
        }
        Map map = new HashMap();

        for (int i = 0; i < data.length; i += 2) {
            map.put(data[i], data[i + 1]);
        }

        return map;
    }
}

Related

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