package com.java13.myjava;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.junit.Test;
public class Maptest {
@Test
public void teste1() {
//創建map集合
Map<String,String> map=new HashMap<String,String>();
//会有四个
map.put("Key01", "tom");
map.put("Key01", "tomsas");
map.put("Key03", "tomsasc");
map.put("Key04", "tomsascc");
map.put("Key05", "tomsasfff");
//System.out.println(map.size());
/**
* 遍历map集合1
*/
/**Set<Entry<String, String>> entrySet= map.entrySet();
Iterator<Entry<String, String>>it=entrySet.iterator();
while (it.hasNext()){
Entry<String, String> entry=it.next();
String key =entry.getKey();
String value=entry.getValue();
System.out.println(key+"-"+value);
}*/
/**
* 遍历map集合2 entrySet取键值对的集合
*/
Set<Entry<String, String>> keyset =map.entrySet();
Iterator<Entry<String, String>> it=keyset.iterator();
while (it.hasNext()){
Entry<String, String> key =it.next();
String value=map.get(key);
System.out.println(key+"-"+value);
}
}
}