Java List to Map listToMap(List> list)

Here you can find the source of listToMap(List> list)

Description

Converts a list of two element lists (key, value) into a map.

License

Open Source License

Parameter

Parameter Description
list the list

Return

a map

Declaration

public static <T> Map<T, T> listToMap(List<List<T>> list) 

Method Source Code


//package com.java2s;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    /**/*  ww  w  .j a  va2s  .  co m*/
     * Converts a list of two element lists (key, value) into a map.
     *
     * @param list the list
     * @return a map
     */
    public static <T> Map<T, T> listToMap(List<List<T>> list) {
        Map<T, T> map = new HashMap<T, T>(list.size());
        Iterator<List<T>> i = list.iterator();
        while (i.hasNext()) {
            List<T> l = i.next();
            map.put(l.get(0), l.get(1));
        }
        return map;
    }
}

Related

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