package fffffr;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class test1 {
public static void main(String[] args) {
Map<String, String> map=new HashMap<>();
map.put("亚亚","Q妹");
map.put("菲菲","Q妹");
map.put("欧欧","Q仔");
map.put("美美","Q妹");
Set<String> keyset=map.keySet();
Iterator<String> iter=keyset.iterator();
while(iter.hasNext()){
String key=iter.next();
String value=map.get(key);
System.out.println(key+" "+value);
}
}
}
package pro2;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Test {
public static void main(String[] args) {
Map<String, String> map = new HashMap();
map.put("yaya", "Q妹");
map.put("feifei", "Q妹");
map.put("ouou", "Q仔");
map.put("meimei", "Q妹");
System.out.println("分别是:");
System.out.println("使用iterator遍历");
Set<String> nameset = map.keySet();
Iterator<String> iter = nameset.iterator();
while (iter.hasNext()) {
String name = iter.next();
String sex = map.get(name);
System.out.println(name + " " + sex);
}
System.out.println("使用foreach遍历");
for (String name : nameset) {
String sex = map.get(name);
System.out.println(name + " " + sex);
}
}
}