java如何对HashMap遍历呢?
下文笔者讲述使用java代码对HashMap遍历的方法分享,如下所示
HashMap遍历的方法
HashMap遍历的实现思路:
使用hashmap的values()方法获取HashMap中的所有值
然后使用while循环对其进行遍历
即可打印出HashMap中的值
例:HashMap遍历的示例分享
/**
* java265.com HashMap遍历
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
HashMap<String, String> hMap = new HashMap<String, String>();
hMap.put("1", "Java爱好者");
hMap.put("2", "java265.com");
hMap.put("3", "我最爱java了!");
Collection cl = hMap.values();
Iterator itr = cl.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


