Java List to Map listToMap(List> list)

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

Description

Puts the entries in list into a Map .

License

Open Source License

Parameter

Parameter Description
list a parameter

Declaration

private static <A, B> Map<A, B> listToMap(List<Map.Entry<A, B>> list) 

Method Source Code

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

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {
    /**//from   ww  w .  j  a  v  a 2s .  c  om
     * Puts the entries in {@code list} into a {@code Map}. The returned map has
     * the same iteration order over entries as {@code list}.
     * 
     * @param list
     * @return
     */
    private static <A, B> Map<A, B> listToMap(List<Map.Entry<A, B>> list) {
        Map<A, B> result = new LinkedHashMap<A, B>();
        for (Iterator<Map.Entry<A, B>> it = list.iterator(); it.hasNext();) {
            Map.Entry<A, B> entry = (Map.Entry<A, B>) it.next();
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }
}

Related

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