Java Mapのkey , value をforループで
1.サンプル
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap();
map.put("1","aaa") ;
map.put("2","bbb") ;
map.put("3","ccc") ;
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
}
}
}
2.実行結果
1 : aaa
2 : bbb
3 : ccc
と表示されました。
PR