Here you can find the source of toMap(ResultSet rs, List wantedColumnNames)
public static final Map toMap(ResultSet rs, List wantedColumnNames) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Main { public static final Map toMap(ResultSet rs, List wantedColumnNames) throws SQLException { Map columns = new LinkedHashMap(); // Set up the map of columns int numWantedColumns = wantedColumnNames.size(); for (int i = 0; i < numWantedColumns; ++i) { List columnValues = new ArrayList(); columns.put(wantedColumnNames.get(i), columnValues); }/*from w w w .ja v a 2 s. c om*/ while (rs.next()) { for (int i = 0; i < numWantedColumns; ++i) { String columnName = (String) wantedColumnNames.get(i); Object value = rs.getObject(columnName); List columnValues = (List) columns.get(columnName); columnValues.add(value); columns.put(columnName, columnValues); } } return columns; } }