「java」インタフェース Map.Entryを使うサンプル
構文
for (Entry<String, String> 変数名 : マップ名.entrySet())
Javaコード
package com.arkgame.study.mvc; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class EntryDemo { public static Map<String, String> hp = new HashMap<String, String>(); public static void main(String[] args) { String keyLstA[] = { "Key01", "Key02", "Key03", "Key04" }; String valLstB[] = { "A001", "B002", "C003", "D004" }; for (int i = 0; i < keyLstA.length; i++) { hp.put(keyLstA[i], valLstB[i]); } for (Entry<String, String> ent : hp.entrySet()) { System.out.println("key: " + ent.getKey() + " value:" + ent.getValue()); } } }
結果
key: Key01 value:A001
key: Key02 value:B002
key: Key03 value:C003
key: Key04 value:D004