Map类的使用
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class demo8 {
public static void main(String[] args) {
LinkedHashMap<String, String> m = new LinkedHashMap<String,String>();
m.put("1", "a");
m.put("2", "a2");
m.put("3", "a66");
m.put("4", "a23");
m.put("5", "a4");
System.out.println(m);
fun2();
}
public static void fun1() {
Map<Integer, String> d = new HashMap<Integer,String>();
d.put(1, "张无忌");
d.put(2, "张无忌2");
d.put(3, "张无忌3");
d.put(4, "张无忌4");
d.put(5, "张无忌5");
d.put(100000, "张无忌6");
System.out.println(d);
String s = d.remove(1);
System.out.println(s);
System.out.println(d);
String aString = d.get(4);
System.out.println(aString);
}
public static void fun2() {
Map<String, String> m= new HashMap<>();
m.put("班草","王家宝");
m.put("班草1","朱东洋");
m.put("班草2","韩鹏欢");
Set<String> s= m.keySet();
Iterator<String> it = s.iterator();
// while (it.hasNext()) {
// String key = it.next();
// String value=m.get(key);
// System.out.println(key);
// System.out.println(value);
// }
for (String didi:m.keySet()) {
String in = m.get(didi);
System.out.println(didi+" "+in);
}
}
}