6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Java Mapをループさせる方法(forEach / 拡張for文)

Last updated at Posted at 2019-12-09

JavaでMapをループさせる方法をメモ

Map<String, String> map = new HashMap<>();
// mapのkey,valueのset処理は省略

// forEachのパターン
map.forEach((k, v) -> {
    System.out.println(k);
    System.out.println(v);
});

// 拡張for文のパターン
for(Map.Entry<String, String> entry : map.entrySet()){
    System.out.println(entry.getKey());
    System.out.println(entry.getValue());
}

forEachの方がすっきりして見やすいかも。

6
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?