Java List Create createMapFromList(List list)

Here you can find the source of createMapFromList(List list)

Description

Simple List to HashMap creator

License

Open Source License

Parameter

Parameter Description
list a parameter

Declaration

public static HashMap createMapFromList(List list) 

Method Source Code


//package com.java2s;
/*//from ww  w.  j  av  a2 s .  c o m
 * JBoss, Home of Professional Open Source.
 *
 * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
 *
 * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
 */

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Simple List to HashMap creator 
     * @param list
     * @return
     * @since 5.0
     */
    public static HashMap createMapFromList(List list) {

        HashMap hmap = new HashMap(list.size());
        Iterator iter = list.iterator();

        while (iter.hasNext()) {
            Object oTemp = iter.next();
            hmap.put(oTemp, oTemp);
        }

        return hmap;
    }
}

Related

  1. createListOfObjects(T... elements)
  2. createListOfOneItem(Object item)
  3. createListOfValidNumberOfPoints(int[] terms, int min, int max)
  4. createListWithArray(Object[] array)
  5. createListWithObjects(Object... objects)
  6. createMapOfObjects(List keys, List values)
  7. createMatrix(List source, List target)
  8. createMergedRegex(List regexes)
  9. createMultiParamMessage(String aPrefix, String aSuffix, List aParams)