您好,欢迎访问一九零五行业门户网

Java 实例 - HashMap遍历

以下实例演示了如何使用 collection 类的 iterator() 方法来遍历集合:
/* author by w3cschool.cc main.java */import java.util.*;import java.util.*;public class main { public static void main(string[] args) { hashmap< string, string> hmap = new hashmap< string, string>(); hmap.put("1", "1st"); hmap.put("2", "2nd"); hmap.put("3", "3rd"); collection cl = hmap.values(); iterator itr = cl.iterator(); while (itr.hasnext()) { system.out.println(itr.next()); } }}
以上代码运行输出结果为:
3rd 2nd 1st
以上就是java 实例 - hashmap遍历的内容。
其它类似信息

推荐信息