The value taken out from the database is put into the map in a loop, and then the map is put in the list, asking how to take it out
rs returns the result set for the database
rs is the result set returned by the database query 例:while(rs.next()){ Map dqMap=new HashMap(); dqMap.put("jqh", rs.getString("jqh")); dqMap.put("khh", rs.getString("khh")); dqMap.put("ydmc", rs.getString("ydmc")); dqMap.put("dz", rs.getString("dz")); list.add(dqMap); }
Now how to loop list how to get the value out
for(int i=0;i<list.size();i++) { Map dqMap = (Map)list.get(i); String jqh = dqMap.get('jqh'); String khh = dqMap.get('khh'); }
Note: A method that is used more frequently in development.
Use Cases:
import java.util.Map; import java.util.List; import java.util.ArrayList; import java.util.HashMap; public class ListTest1 { public static void main(String[] args) { List<Map<String,String>> list1= new ArrayList<Map<String,String>>(); Map<String,String> map1= new HashMap<String,String>(); map1.put("bc1", "Spinach"); map1.put("bc2", "Big Spinach"); map1.put("bc3", "Super spinach"); list1.add(map1); //The map object is put into the list collection System.out.println("Output parameter: "); for(int i=0;i<list1.size();i++){ //The list collection loops out the map objects one by one Map<String,String> map2= (Map<String,String>)list1.get(i); String str1=map2.get("bc1"); String str2=map2.get("bc2"); String str3=map2.get("bc3"); System.out.println("bc1:"+str1); System.out.println("bc2:"+str2); System.out.println("bc3:"+str3); } } }