Let's talk about it today Java8 in forEach Simple use of . We should be able to see it more clearly through comparison , Better understanding :
============Java8 The way before ========== Map<String, Integer> items = new HashMap<>();
items.put("A", 10); items.put("B", 20); items.put("C", 30); items.put("D", 40);
items.put("E", 50); items.put("F", 60); for (Map.Entry<String, Integer> entry :
items.entrySet()) { System.out.println("Item : " + entry.getKey() + " Count : "
+ entry.getValue()); } ============forEach + Lambda expression ========== Map<String,
Integer> items = new HashMap<>(); items.put("A", 10); items.put("B", 20);
items.put("C", 30); items.put("D", 40); items.put("E", 50); items.put("F", 60);
items.forEach((k,v)->System.out.println("Item : " + k + " Count : " + v));
items.forEach((k,v)->{ System.out.println("Item : " + k + " Count : " + v);
if("E".equals(k)){ System.out.println("Hello E"); } });
Two ergodic List:
==Java8 The way before
List<String> items = new ArrayList<>(); items.add("A"); items.add("B");
items.add("C"); items.add("D"); items.add("E"); for(String item : items){
System.out.println(item); } ============forEach + Lambda expression ==========
List<String> items = new ArrayList<>(); items.add("A"); items.add("B");
items.add("C"); items.add("D"); items.add("E"); // output :A,B,C,D,E
items.forEach(item->System.out.println(item)); // output : C items.forEach(item->{
if("C".equals(item)){ System.out.println(item); } });
introduce forEach + Lambda After expression , It's a lot less code .

Technology
©2019-2020 Toolsou All rights reserved,
Gude Haowen serial - You deserve to be an engineer ( Preface ) A single key controls multiple water lamp states Bitcoin in ten years ,VDS Opportunity or fraud CSS architecture design Programmer Tanabata Valentine's Day confession code Python+OpenCV Detailed explanation of face recognition technology Bug Can data be used as the basis of technical personnel assessment KPI?Jsp+Ajax+Servlet+Mysql Add, delete, modify and query ( one ) Thorough explanation from Zhongtai Unity Scene loading asynchronously ( Implementation of loading interface )