如何得到map中的KEY和VALUE
答案:1 悬赏:0
解决时间 2021-02-02 06:06
- 提问者网友:刪除丶後
- 2021-02-01 16:13
如何得到map中的KEY和VALUE
最佳答案
- 二级知识专家网友:我们只是兮以城空
- 2021-02-01 17:35
package test;import java.util.*;public class Test_Map {
public static void main(String[] args) throws Exception {
Map map = new HashMap();
map.put("one", 1);map.put("two", 2);
map.put("three", 3);
//得到value的方法
System.out.println("========得到value的方法========");
Collection c = map.values();
System.out.println(c);
Iterator iter1 = (Iterator)map.values().iterator();
while(iter1.hasNext()){
System.out.println(iter1.next());}//得到key的方法
System.out.println("========得到key的方法========");
Collection s = map.keySet();
System.out.println(s);
Iterator iter2 = (Iterator)map.keySet().iterator();
public static void main(String[] args) throws Exception {
Map map = new HashMap();
map.put("one", 1);map.put("two", 2);
map.put("three", 3);
//得到value的方法
System.out.println("========得到value的方法========");
Collection c = map.values();
System.out.println(c);
Iterator iter1 = (Iterator)map.values().iterator();
while(iter1.hasNext()){
System.out.println(iter1.next());}//得到key的方法
System.out.println("========得到key的方法========");
Collection s = map.keySet();
System.out.println(s);
Iterator iter2 = (Iterator)map.keySet().iterator();
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯