//新手笔记提醒
package TestMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class TestMap {
public static void main(String[]args){
HashMap<String,String> hm=new HashMap<String,String>();
//将abc将入集合 它的键是01
hm.put("01","abc");
hm.put("00","abcd");
//当存入的数据已有时,会覆盖键对应的之前值,方法的返回值时被取代的值
System.out.println(hm.put("01","aaaaaaaaaaaaaaa"));
//size()表示集合元素的个数
System.out.println(hm.size());
//删除对应键值的数据 返回值是被删除的键
System.out.println(hm.remove("01"));
System.out.println(hm);
//通过传入的键获取到它对应的值
System.out.println(hm.get("00"));
//判断集合是否包含某个键
System.out.println("いるのか?"+hm.containsKey("001"));
//判断是否包含某个值
System.out.println("いるのか?"+hm.containsValue("abc"));
//以下未成品
//将集合里面的所有键取出放入到一个Set集合
Set<String> keyset=hm.keySet();
for (java.util.Iterator iterator = keyset.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
String key =(String)iterator.next();
//
Set<Entry<String,String>> entrySet=Map.entrySet();
for(Iterator<Entry<String,String>>iterator1=entrySet.iterator();iterator1.hasNext();){
//遍历映射项
Entry<String,String> entry=iterator1.next();
System.out.println(entry.getKey()+"***"+entry.getValue());
}
}
}
}
public static void main(String[]args){
HashMap<String,String> hm=new HashMap<String,String>();
//将abc将入集合 它的键是01
hm.put("01","abc");
hm.put("00","abcd");
//当存入的数据已有时,会覆盖键对应的之前值,方法的返回值时被取代的值
System.out.println(hm.put("01","aaaaaaaaaaaaaaa"));
//size()表示集合元素的个数
System.out.println(hm.size());
//删除对应键值的数据 返回值是被删除的键
System.out.println(hm.remove("01"));
System.out.println(hm);
//通过传入的键获取到它对应的值
System.out.println(hm.get("00"));
//判断集合是否包含某个键
System.out.println("いるのか?"+hm.containsKey("001"));
//判断是否包含某个值
System.out.println("いるのか?"+hm.containsValue("abc"));
//以下未成品
//将集合里面的所有键取出放入到一个Set集合
Set<String> keyset=hm.keySet();
for (java.util.Iterator iterator = keyset.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
String key =(String)iterator.next();
//
Set<Entry<String,String>> entrySet=Map.entrySet();
for(Iterator<Entry<String,String>>iterator1=entrySet.iterator();iterator1.hasNext();){
//遍历映射项
Entry<String,String> entry=iterator1.next();
System.out.println(entry.getKey()+"***"+entry.getValue());
}
}
}
}