import java.util.HashMap ;import java.util.Map.Entry ;
class
Main
{public static void
main
( String [ ]args
) {// 创建一个HashMap
HashMap
< String, Integer
>numbers
= newHashMap
<> ( ) ;numbers.
put ( "One",
1 ) ;numbers.
put ( "Two",
2 ) ;numbers.
put ( "Three",
3 ) ;System
.
out.
println ( "HashMap: " +numbers
) ;// 访问 HashMap 中的每一个映射项
System
.
out.
print ( "Entries: " ) ;// entrySet()返回了 HashMap 中所有映射项的一个 set 集合视图
// for-each loop 在该视图中访问了每一映射项
for (
Entry
< String, Integer
>entry
:numbers.
entrySet ( ) ) {System
.
out.
print (entry
) ;System
.
out.
print ( ", " ) ;}
}
}
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/6084.html