public class Java8 {
public static void main(String[] args) {
Map<String,String> items=CreateMap();
System.out.println("1........entrySet遍历map......");
for(Map.Entry<String, String> entity:items.entrySet()){
System.out.println(entity.getKey()+":::"+entity.getValue());
}
System.out.println("2........keySet 遍历map......");
for(String key:items.keySet()){
System.out.println(key+":::"+items.get(key));
Iterator<Map.Entry<String, String>> it=items.entrySet().iterator();
//Iterator<Entry<String, String>> it=items.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,String> entity =it.next();
System.out.println(entity.getKey()+":::"+entity.getValue());
}
System.out.println("3........map.value()......");
for(String value:items.values()){
System.out.println("::"+value);
}
System.out.println("3........java8遍历map......");
items.forEach((k,v)->{
System.out.println(k+"::"+v);
if(k.equals("A")){
System.out.println("AAAAA");
}
}
);
}
private static Map<String,String> CreateMap(){
Map<String,String> items=new HashMap<>();
items.put("A", "AAA");
items.put("B", "BBB");
items.put("C", "CCC");
items.put("D", "DDD");
items.put("E", "EEE");
return items;
}
}
public static void main(String[] args) {
Map<String,String> items=CreateMap();
System.out.println("1........entrySet遍历map......");
for(Map.Entry<String, String> entity:items.entrySet()){
System.out.println(entity.getKey()+":::"+entity.getValue());
}
System.out.println("2........keySet 遍历map......");
for(String key:items.keySet()){
System.out.println(key+":::"+items.get(key));
}
//适合大数据量
System.out.println("3........构造器iterator......");Iterator<Map.Entry<String, String>> it=items.entrySet().iterator();
//Iterator<Entry<String, String>> it=items.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,String> entity =it.next();
System.out.println(entity.getKey()+":::"+entity.getValue());
}
System.out.println("3........map.value()......");
for(String value:items.values()){
System.out.println("::"+value);
}
System.out.println("3........java8遍历map......");
items.forEach((k,v)->{
System.out.println(k+"::"+v);
if(k.equals("A")){
System.out.println("AAAAA");
}
}
);
}
private static Map<String,String> CreateMap(){
Map<String,String> items=new HashMap<>();
items.put("A", "AAA");
items.put("B", "BBB");
items.put("C", "CCC");
items.put("D", "DDD");
items.put("E", "EEE");
return items;
}
}