**map集合的四种遍历方法**
public class Mapper {
static Map<String,Object> linkedMap =new LinkedHashMap<String, Object>();
static Map<String,String> hashmap=new HashMap<String, String>();
static {
linkedMap.put("first_wife","jujingyi");
linkedMap.put("secand_wife","fengtimo");
linkedMap.put("third_wife","zholiying");
hashmap.put("first_wife","jujingyi");
hashmap.put("secand_wife","fengtimo");
hashmap.put("third_wife","zholiying");
}
//第一种循环
@Test
public void curculationOne(){
Set<String> hashmapkeyset = hashmap.keySet();
for (String s : hashmapkeyset) {
System.out.println(hashmap.get(s));
}
}
//第二种循环
@Test
public void curculationTwo(){
Set<Map.Entry<String, String>> entries = hashmap.entrySet();
for (Map.Entry<String, String> entry : entries) {
String value = entry.getValue();
System.out.println(value);
}
}
//第三种循环
@Test
public void curculationThree(){
Collection<String> values = hashmap.values();
for (String value : values) {
System.out.println(value);
}
}
//第四种循环 迭da器
@Test
public void curculationFour(){
Iterator<Map.Entry<String, String>> iterator = hashmap.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, String> next = iterator.next();
System.out.println(next.getValue());
}
}
}