[Java] forEach method

public class Array {

	public static void main(String[] args) {
		List<Employee> list = new ArrayList<Employee>();
		list.add(new Employee("tanaka", 25));
		list.add(new Employee("yamada", 28));
		list.add(new Employee("suzuki", 20));

		list.forEach( s -> System.out.println(s.getName() + ":" + s.getAge()));

When there is one repeating execution process, it can be written in one line like this, but when there are multiple execution processes, enclose the execution process with {}

		list.forEach( s -> {

The way to write without using a lambda expression is as follows

		list.forEach(new Consumer<Employee>() {
			public void accept(Employee e) {
				System.out.println(e.getName() + " : " + e.getAge());

Recommended Posts

[Java] forEach method
Java method
java (method)
Java method
[Java] method
[Java] method
Java8 method reference
java8 method reference
[Java] Random method
[Java] split method
JAVA DB connection method
Java learning 2 (learning calculation method)
Java learning memo (method)
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Java programming (class method)
[Java] Basic method notes
[Java] New Thread generation method (2)
Java GC method determination conditions
Create a java method [Memo] [java11]
Java test code method collection
[Java Silver] About equals method
[Java] Timer processing implementation method
[Java] Random number generation method (Random)
Java methods and method overloads
Benefits of Java static method
[Java Silver] Array generation method
[Java] New Thread generation method (1)
[Java] Stream (filter, map, forEach, reduce)
[Java] Object-oriented syntax --class method / argument
Automatic photo resizing method in Java
Java method list (memorial) (under construction)
[Java] How to use join method
Screen transition by Post method [Java]
[Java] Object-oriented syntax-class / field / method / scope
Java comparison using the compareTo () method
[Java beginner] == operator and equals method
Try to extract java public method
Try using IBM Java method tracing
[Java] Proxy setting method when starting Java
Java beginner design pattern (Factory Method pattern)
[Java] Processing time measurement method memo
Call the super method in Java
Implementation of clone method for Java Record
My thoughts on the equals method (Java)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
Java runtime environment construction method (Tomcat @ Linux)
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
java (constructor)