java编程基础之集合中嵌套集合时数据的读取

import java.util.*;

class  Maptest
{
	public static void main(String[] args) 
	{	
		TreeMap> tm = new TreeMap>();

		TreeMap tm1 =new TreeMap();
		tm1.put("01","zhangsan1");
		tm1.put("02","zhangsan2");
		tm1.put("03","zhangsan3");

		TreeMap tm2 =new TreeMap();
		tm2.put("01","zhangsan4");
		tm2.put("02","zhangsan5");
		tm2.put("03","zhangsan6");
		tm.put("01",tm1);
		tm.put("02",tm2);
		Iterator it = tm.keySet().iterator();
		while(it.hasNext())
		{
			String str = it.next();
			TreeMap t = tm.get(str);
			sop(str);
			getStudentInfo(t);
		}
	}
	public static void getStudentInfo(TreeMap tm)
	{
		Iterator it = tm.keySet().iterator();
		while(it.hasNext())
		{
			String id = it.next();
			String name = tm.get(id);
			sop(id+"......."+name);
		}
	}
	public static void sop(Object obj)
	{
		System.out.println(obj);
	}
}

你可能感兴趣的:(java编程基础之集合中嵌套集合时数据的读取)