代码:
package com.wyl; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; public class aaa { public static void main(String[] args) { // location 1 List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Map<String,Object> map = new HashMap<String,Object>(); String a = "23"; System.out.println(a); for(int i=0;i<10;i++){ //location 2 // Map<String,Object> map = new HashMap<String,Object>(); map.put("age", "xiaoming:"+i); System.out.println("=========:"+i); list.add(map); } Iterator it = list.iterator(); while(it.hasNext()){ Map m = (Map)it.next(); String age = (String) m.get("age"); System.out.println("age:"+age); } } }
分别在location1和location2出实例化出map,打印出来的数值就是不一样。
时间: 2024-12-25 03:22:02