Here you can find the source of readFile(List
public static List<Map<String, String>> readFile(List<String> fieldNames, String filename) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { public static List<Map<String, String>> readFile(List<String> fieldNames, String filename) throws IOException { List<Map<String, String>> rows = new ArrayList<Map<String, String>>(); FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); br.lines().forEach(values -> { String[] vs = values.split(" "); Map<String, String> row = new HashMap<String, String>(); for (int i = 0; i < fieldNames.size(); i++) { row.put(fieldNames.get(i), vs[i]); }/*from w w w . ja v a 2s . co m*/ rows.add(row); }); br.close(); fr.close(); return rows; } }