首页javamapJava Collection - 如何从HashMap中提取值

Java Collection - 如何从HashMap中提取值

我们想知道如何从HashMap中提取值。
import java.util.HashMap;

public class Main {
  public static void main(String args[]) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

    map.put(1, 2);
    map.put(2, 3);
    map.put(3, 4);

    for (Integer key : map.keySet()) {
      System.out.println(map.get(key));
    }
  }
}