Java List to Map listToMap(Object... objects)

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

Description

list To Map

License

Open Source License

Declaration

@SuppressWarnings({ "unchecked", "rawtypes" })
    public static <K, V> Map<K, V> listToMap(Object... objects) 

Method Source Code


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

import java.util.*;

public class Main {
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static <K, V> Map<K, V> listToMap(Object... objects) {
        HashMap map = new HashMap();
        Object key = null;/*w  ww.  j a  v  a2  s  .c  o  m*/
        for (final Object object : objects) {
            if (key == null) {
                key = object;
            } else {
                map.put(key, object);
                key = null;
            }
        }
        return map;
    }
}

Related

  1. listToMap(final String... strings)
  2. listToMap(List input)
  3. listToMap(List> list)
  4. listToMap(List> list)