Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;

import java.util.List;
import java.util.Map;

public class Main {
    /**
     * 
     * pre : resultSet must be a valid List&lt;Map&gt; <br>
     * post : a Map&lt;keyValue, Map&gt;
     * 
     * @param resultSet
     *          result set from sql. no need order by
     * @param key
     *          the key to get the value to be the new key for the returned map
     * @return null if resultSet is null
     */
    @SuppressWarnings("rawtypes")
    public static Map<Object, Map> sqlListToMapWithUniqueKey(List<Map> resultSet, String key) {

        if (resultSet == null)
            return null;

        Map<Object, Map> rs = new HashMap<Object, Map>(resultSet.size());
        for (Map map : resultSet) {
            rs.put(map.get(key), map);
        }
        return rs;
    }
}