jdk8及以上 foreach遍歷map和list
阿新 • • 發佈:2019-02-16
//foreach功能,遍歷Map
public void queryMapExt(Map<String,Object> map){
map.forEach((k,v)->{
System.out.println("Item : " + k + " Count : " + v);
System.out.println(Objects.equals(k, "E"));
if("E".equals(k)){
System.out.println("Hello E");
}
});
}
//遍歷list
public void queryMapExt(List<Object> list){
list.forEach(item->{
System.out.println("Item : " + item);
if("E".equals(item)){
System.out.println("E");
}
});
}
public void queryMapExt(Map<String,Object> map){
map.forEach((k,v)->{
System.out.println("Item : " + k + " Count : " + v);
System.out.println(Objects.equals(k, "E"));
if("E".equals(k)){
System.out.println("Hello E");
}
});
}
//遍歷list
public void queryMapExt(List<Object> list){
list.forEach(item->{
System.out.println("Item : " + item);
if("E".equals(item)){
System.out.println("E");
}
});
}