Map的几种取值方法


 

public static void main(String[] args) throws IOException,ParseException {

Map<String,String> m = new HashMap<String,String>();

m.put("1", "haha");

m.put("2", "hehe");

m.put("3", "heihei");

 

 

 //第一种

for(String k : m.keySet())

{

System.out.println(k+m.get(k));

}

 

 //第二种

for(Map.Entry<String, String> d:m.entrySet())

{

System.out.println(d.getValue()+d.getKey());

}

 

 //第三种

Set<String> x = m.keySet();

 

Iterator it = x.iterator();

while(it.hasNext())

{

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

System.out.println(u+m.get(u));

}

 

 //第四种

Set<Map.Entry<String, String>> y = m.entrySet();

 

Iterator<Map.Entry<String, String>>  it1 = m.entrySet().iterator();

while(it1.hasNext())

{

Map.Entry<String, String> en = it1.next();

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

}

 

 

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM