package test62;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Map.Entry;
public class test1 {
public static void main(String[] args) {
String str1 = new String("xx");
String str2 = new String("xx");
System.out.println(str1 == str2);
Map<String ,String> map = new IdentityHashMap<String ,String>();
map.put(str1, "hello");
map.put(str2, "world");
for(Entry<String,String> entry : map.entrySet())
{
System.out.println(entry.getKey()+" " + entry.getValue());
}
System.out.println(" containsKey---> " + map.containsKey("xx"));
System.out.println("str1 containsKey---> " + map.containsKey(str1));
System.out.println("str2 containsKey---> " + map.containsKey(str2));
System.out.println(" value----> " + map.get("xx"));
System.out.println("str1 value----> " + map.get(str1));
System.out.println("str2 value----> " + map.get(str2));
}
}
我们的看看输出的结果为:
false
xx world
xx hello
containsKey---> false
str1 containsKey---> true
str2 containsKey---> true
value----> null
str1 value----> hello
str2 value----> world
Map 一个key其实可以保存多个value
最新推荐文章于 2024-07-31 17:36:20 发布