Map集合的使用
package cn.itxdl.day16;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class MapTest {
public static void main(String[] args) {
Map<Integer, String> m1 = new HashMap<Integer, String>();
System.out.println("m1 = " + m1);
System.out.println("--------------------------------------");
String str1 = m1.put(1, "one");
System.out.println("str1 = " + str1);
System.out.println("m1 = " + m1);
str1 = m1.put(2, "two");
System.out.println("str1 = " + str1);
System.out.println("m1 = " + m1);
str1 = m1.put(3, "three");
System.out.println("str1 = " + str1);
System.out.println("m1 = " + m1);
System.out.println("--------------------------------------");
String str2 = m1.put(1, "eleven");
System.out.println("str2 = " + str2);
System.out.println("m1 = " + m1);
System.out.println("--------------------------------------");
String str3 = m1.get(1);
System.out.println("str3 = " + str3);
str3 = m1.get(11);
System.out.println("str3 = " + str3);
boolean b1 = m1.containsKey(1);
System.out.println("b1 = " + b1);
b1 = m1.containsKey(11);
System.out.println("b1 = " + b1);
b1 = m1.containsValue("one");
System.out.println("b1 = " + b1);
b1 = m1.containsValue("eleven");
System.out.println("b1 = " + b1);
System.out.println("--------------------------------------");
String str4 = m1.remove(11);
System.out.println("str4 = " + str4);
str4 = m1.remove(1);
System.out.println("str4 = " + str4);
System.out.println("--------------------------------------");
System.out.println("m1 = " + m1);
System.out.println("--------------------------------------");
Set<Integer> s1 = m1.keySet();
for(Integer ti : s1) {
System.out.println(ti + "=" + m1.get(ti));
}
System.out.println("--------------------------------------");
Set<Map.Entry<Integer,String>> s2 = m1.entrySet();
for(Map.Entry<Integer,String> me : s2) {
System.out.println(me.getKey() + "=" + me.getValue());
}
}
}