Container is used to store data, both of the two containers will be used herein to store a data table.
The container may be used any container, choose the right, to meet the demand.
This case is a container used: Column: Use the Map Line: Use List
Target table shows:
Code:
To one word: ORM Object Relational Mapping
_20191213 Package; Import of java.util.ArrayList; Import the java.util.HashMap; Import the java.util.Iterator; Import java.util.List; Import a java.util.Map; / ** * use the container to store a table * @ TEDU author * List stored in the Map * / public class ContainerDemo { public static void main (String [] args) { // table row: use ArrayList, rank List <Map <String, Object >> row = new ArrayList <> (); // table columns: use Map, the data corresponding to the key up the Map <String, Object> = new new column1 the HashMap <> (); column1.put ( "ID", 1001); column1.put ( "name" "Joe Smith"); column1.put ( "salary", 20000); column1.put ( "entry date", "2018.05.04"); Map<String,Object> column2 = new HashMap<>(); column2.put("ID",1002); column2.put("姓名","李四"); column2.put("薪水",12000); column2.put("入职日期","2014.04.14"); Map<String,Object> column3 = new HashMap<>(); column3.put("ID",1003); column3.put("王五","张三"); column3.put("薪水",21000); column3.put("入职日期","2013.11.04"); //将每一条记录添加到行中 row.add(column1); row.add(column2); row.add(column3); for(int i = 0;i < row.size();i++) { Iterator it = row.get(i).entrySet().iterator(); while(it.hasNext()) { System.out.print(it.next()+" "); } System.out.println(); } } }