在 JAVA 中迭代 HashMap 时出现编译错误

问题描述

迭代一个HashMap

我正在尝试在我的 M1 Macbook Air 机器上的 Visual Studio 代码中执行以下代码。但是得到这些错误。虽然代码在在线IDE中执行。

/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/bin/java --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 -cp "/Users/shoumik /Library/Application Support/Code/User/workspaceStorage/c7518cbb3ce46c96e642c654a9524389/redhat.java/jdt_ws/jdt.ls-java-project/bin”测试 线程“main”中的异常 java.lang.Error: 未解决的编译问题: Map 类型中的 entrySet() 方法引用了缺失的 Set

类型
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.swing.text.html.parser.Entity;

class Test {
    public static void main(String[] args) {
        Map<String,Integer> hm = new HashMap<String,Integer>();
        hm.put("abc",123);
        hm.put("def",321);
        hm.put("ghi",33);

        
        Iterator<Entry<String,Integer>> hmIterator = hm.entrySet().iterator();

        while(hmIterator.hasNext()) {
            Entry<String,Integer> entries = hmIterator.next();
            System.out.println("Key is" + entries.getKey());
            System.out.println("Value is " + entries.getValue());
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)