当前位置: 首页 > 工具软件 > inMap > 使用案例 >

map<Strng map<string map>>类型的值获取

冀阳文
2023-12-01

废话不多说,例子说明:

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

public class Map1
{
  public static void main(String[] args)
  {

    Map map = new HashMap<String, Object>();
    Map map1 = new HashMap<String, Object>();
    map.put("11", "fds");
    map.put("21", "valu");
    map.put("31", "wes");
    map.put("41", "hjk");
    map1.put("51", "fds44");
    map1.put("61", "valu3");
    map1.put("71", "wes2");
    map1.put("81", "hjk1");

    Map<String, Map<String, Object>> map11 = new LinkedHashMap<String, Map<String, Object>>();

    map11.put("123", map);
    map11.put("456", map1);

    Iterator outIter = map11.keySet().iterator();
    while (outIter.hasNext())// 迭代外层map
    {
      Object o = outIter.next();
      String key1 = o.toString();
      System.out.println("***************************" + key1);

      Map inMap = (Map) map11.get(o);// 获取内层map
      Iterator inIter = inMap.keySet().iterator();// 迭代内层map
      while (inIter.hasNext())
      {
        String key = inIter.next().toString();
        String value = (String) inMap.get(key);
        System.out.println(key + "=" + value);
      }
    }
  }
}

 类似资料: