ArrayListHashmap嵌套

package arrayListHashMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

public class ArrayListHashMap {
	
	public static void main(String[] args) {
		ArrayList<HashMap<String, Object>> chaoba =new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> map=new HashMap<String, Object>();
		
  
  map.put("1", "a");//添加
 // chaoba.add(map);//添加进数组
  map.put("2", "b");
  //chaoba.add(map);
  map.put("3", "ch");
  map.put("4", "ch1");
 // chaoba.add(map);
  map.remove("3");//删除
  map.put("1", "c");//修改采用覆盖
 
  chaoba.add(map);  //添加到动态数组中存在
  System.out.println(chaoba);
  for(HashMap<String, Object> ch:chaoba)
  {
	  for (Entry<String, Object> entry : map.entrySet()) {
		  System.out.println(entry.getKey() + " " + entry.getValue());
		  }
	
  }
  /*
   * Map类提供了一个称为entrySet()的方法,这个方法返回一个Map.Entry实例化后的 对象集。
   * 接着,Map.Entry类提供了一个getKey()方法和一个getValue()方法,
   * 
Map.Entry同时也提供了一个setValue()方法*/
	}

	

}

  

一万年太久,只争朝夕!
原文地址:https://www.cnblogs.com/chaoba/p/6677791.html