map
package l6.e5.map; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class MapTest5My2 { public static void main(String[] args) { HashMap<String,String> map = new HashMap<String,String>(); map.put("a", "aa"); map.put("b", "bb"); map.put("c", "cc"); map.put("d", "dd"); Set<String> set = map.keySet(); //keyset 1 for (String key : set) { System.out.println("key= "+ key + " and value= " + map.get(key)); } //keyset 2 Iterator<String> it=set.iterator(); while (it.hasNext()) { String key = (String) it.next(); String value=map.get(key); System.out.println(key+":"+value); } //entryset Set<Map.Entry<String, String>> set2= map.entrySet(); for (Map.Entry<String, String> entry : set2) { System.out.println("key :" + entry.getKey() + " and value :" + entry.getValue()); } } }