java table data storage

id name salary entry date
1001 Joe Smith 11 2018.5.5
1002 John Doe 10 2018.5.9
1003 Wang Fri 9 2018.9.9
// table each line using Map storage to store the entire table with a list that memory is Map List

Storing tabular data such
ideas: each line using Map storage, use List to store the entire table (all Map)
print when traversing each Map List of key and get to print by obtaining a set of keys in each of the Map (key) value corresponding key

public static void main(String[]args)
{
    Map<String,Object> row1=new HashMap<>();
    row1.put("id","1001");
    row1.put("姓名", "张三");
    row1.put("薪水", "11");
    row1.put("入职日期", "2018.5.5");
    Map<String,Object> row2=new HashMap<>();
    row2.put("id","1002");
    row2.put("姓名", "李四");
    row2.put("薪水", "10");
    row2.put("入职日期", "2018.5.9");
    Map<String,Object> row3=new HashMap<>();
    row3.put("id","1003");
    row3.put("姓名", "王五");
    row3.put("薪水", "9");
    row3.put("入职日期", "2018.9.9");

    List<Map<String,Object>> table=new ArrayList<>(); //在List内存放Map
    table.add(row1);
    table.add(row2);
    table.add(row3);

    for(Map<String,Object>row :table)  //获得每一行
    {
        Set<String> key=row.keySet();   //获得当行的key的集合
        for(String s:key)
        {
            System.out.print(s+":"+row.get(s)+ "\t");    //获得键值和键所对应的值
        }
        System.out.println();
    }
}

Guess you like

Origin blog.51cto.com/14437184/2422178