for循环取出类中Map值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了for循环取出类中Map值相关的知识,希望对你有一定的参考价值。

方法有两种:

第一种:简单

for(Entry<String,类> en:实例.getMap变量方法().setEntry())

{

System.out.println(en.getKey()+" "+en.getValue());

}

第二种:迭代器

Map<String,类>  ma=实例.getMap变量方法();

Iterator it = ma.keySet().iterator();

while(it.hasnext())

{

String key =(String) it.next();

类 em=ma.get(key);

System.out.println("key"+key+" "+em.getName() );

}

 

以上是关于for循环取出类中Map值的主要内容,如果未能解决你的问题,请参考以下文章