java.util.Map.keySet()関数の使い方

2021年6月28日

サンプルコード
package study;

import java.util.HashMap;
import java.util.Map;

public class MapDemoKu {

public static void main(String[] args) {
Map<String, String> city = new HashMap<String, String>();

city.put(“oosaka", “大阪");
city.put(“tokyo", “東京");
city.put(“fukuoka", “福岡");
city.put(“kawasaki", “川崎");
city.put(“nagoya", “名古屋");

System.out.println(city.keySet());

System.out.println(“—–********—–“);
for (String g : city.keySet()) {
String cft = city.keySet().toString();
System.out.println(cft + city.get(g));
}

}

}

実行結果
[tokyo, fukuoka, kawasaki, oosaka, nagoya]
—–********—–
[tokyo, fukuoka, kawasaki, oosaka, nagoya]東京
[tokyo, fukuoka, kawasaki, oosaka, nagoya]福岡
[tokyo, fukuoka, kawasaki, oosaka, nagoya]川崎
[tokyo, fukuoka, kawasaki, oosaka, nagoya]大阪
[tokyo, fukuoka, kawasaki, oosaka, nagoya]名古屋

Java

Posted by arkgame