WARNING
As mentioned in comments, Using peek() for production code is considered bad practice
The reasson is that "According to its JavaDocs, the intermediate Stream operation java.util.Stream.peek() “exists mainly to support debugging” purposes."
As a consequence, this proposed solution SHOULD NOT be used.


Forgot to relate to the first code snippet. I wouldn't use forEach at all. Since you are collecting the elements of the Stream into a List, it would make more sense to end the Stream processing with collect. Then you would need peek in order to set the ID.

List<Entry> updatedEntries = 
    entryList.stream()
             .peek(e -> e.setTempId(tempId))
             .collect (Collectors.toList());

For the second snippet, forEach can execute multiple expressions, just like any lambda expression can :

entryList.forEach(entry -> {
  if(entry.getA() == null){
    printA();
  }
  if(entry.getB() == null){
    printB();
  }
  if(entry.getC() == null){
    printC();
  }
});

However (looking at your commented attempt), you can't use filter in this scenario, since you will only process some of the entries (for example, the entries for which entry.getA() == null) if you do.

Answer from Eran on Stack Overflow
🌐
W3Schools Blog
w3schools.blog › home › java 8 lambda expression multiple statements
Java 8 lambda expression multiple statements - w3schools.blog
April 14, 2018 - Java 8 lambda expression multiple statements example program code in eclipse. Lambda expression is used to provide the implementation of functional interface.
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-we-write-a-multiline-lambda-expression-in-java
How can we write a multiline lambda expression in Java?
([comma seperated argument-list]) -> { multiline statements } interface Employee { String displayName(String s); } public class MultilineLambdaTest { public static void main(String[] s) { Employee emp = (x) -> { // Lambda Expression with multiple lines x = "Jai " + x; System.out.println(x); return x; }; emp.displayName("Adithya"); } }
🌐
Medium
medium.com › @marcelogdomingues › java-lambda-expressions-techniques-for-advanced-developersava-lambda-expressions-techniques-for-c1d71c30bb1f
Java Lambda Expressions: Techniques for Advanced Developersava Lambda Expressions: Techniques for…
June 21, 2024 - Body: The body can be a single expression or a block of statements. If the body is a single expression, the return keyword and curly braces can be omitted. ... Before lambda expressions, implementing functional interfaces required creating anonymous inner classes. This approach often led to verbose and less readable code. Example: Sorting a List Using an Anonymous Inner Class · import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; public class TraditionalExample { public static void main(String[] args) { List<String> names = Arrays.asList("John", "Jane", "Jack", "Jill"); Collections.sort(names, new Comparator<String>() { @Override public int compare(String a, String b) { return a.compareTo(b); } }); for (String name : names) { System.out.println(name); } } }
🌐
W3Schools
w3schools.com › java › java_lambda.asp
Java Lambda Expressions
The simplest lambda expression contains a single parameter and an expression: ... Simple expressions must return a value immediately. They cannot contain multiple statements, such as loops or if conditions.
🌐
Javatpoint
javatpoint.com › java-lambda-expressions
Java Lambda Expressions
October 16, 2016 - Java Lambda Expressions Tutorial with examples and topics on functional interface, anonymous class, lambda for list, lambda for comparable, lambda for runnable, lambda for single argument methods, lambda for multiple arguments methods etc.
🌐
O'Reilly
oreilly.com › library › view › functional-programming-in › 9781941222690 › f_0088.html
Creating a Multiline Lambda Expression - Functional Programming in Java [Book]
February 19, 2014 - Creating a Multiline Lambda Expression​ FileWriterEAM.use(​"eam2.txt"​, writerEAM -> {​ writerEAM.writeStuff(​"how"​);​ writerEAM.writeStuff(​"sweet"​);​ ... - Selection from Functional Programming in Java [Book]
Author   Venkat Subramaniam
Published   2014
Pages   160
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Which method will be invoked in the following statement? ... The method invoke(Callable<T>) will be invoked because that method returns a value; the method invoke(Runnable) does not. In this case, the type of the lambda expression () -> "done" is Callable<T>.
🌐
Jenkov
jenkov.com › tutorials › java › lambda-expressions.html
Java Lambda Expressions
If the method you match your Java lambda expression against takes multiple parameters, the parameters need to be listed inside parentheses.
🌐
GeeksforGeeks
geeksforgeeks.org › java › lambda-expressions-java-8
Java Lambda Expressions - GeeksforGeeks
This is a zero-parameter lambda expression! ... It is not mandatory to use parentheses if the type of that variable can be inferred from the context. Parentheses are optional if the compiler can infer the parameter type from the functional interface. ... import java.util.ArrayList; public class GFG{ public static void main(String[] args){ ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); System.out.println("All elements:"); list.forEach(n -> System.out.println(n)); System.out.println("Even elements:"); list.forEach(n -> { if (n % 2 == 0) System.out.println(n); }); } }
Published   2 weeks ago
🌐
Medium
medium.com › @lavishj77 › java-lambda-expressions-4ea3b8245196
Java Lambda Expressions. One of the big new feature added in… | by Lavish Jain | Medium
January 21, 2022 - 2. No need to mention argument ... an expression — that is, a statement or multiple statements — you’ll need to use the curly braces () -> {int a = 1; System.out.println(a);} (a,b) -> {int sum=a+b; return sum...
🌐
CodingTechRoom
codingtechroom.com › question › java-8-lambda-streams-foreach-multiple-statements
How to Use Java 8 Lambda Streams with forEach for Multiple Statements? - CodingTechRoom
In Java 8, the forEach method can indeed execute only a single statement per Lambda expression. However, you can achieve multiple operations within this context by using a block body or by breaking the operations into smaller functional methods that encapsulate the required logic.
🌐
Programiz
programiz.com › java-programming › lambda-expression
Java Lambda Expressions (With Examples)
In Java, the lambda body is of two types. ... This type of lambda body is known as the expression body. ... This type of the lambda body is known as a block body. The block body allows the lambda body to include multiple statements.
🌐
Stackabyte
stackabyte.com › tutorials › Java › java-lambda-expressions-tutorial
Java Lambda Expressions: Complete Guide with Examples | Stack a Byte
June 21, 2025 - // One parameter, returns its square x -> x * x // Multiple parameters, returns their sum (x, y) -> x + y // With explicit type declarations (int x, int y) -> x + y // With multiple statements in body (String s) -> { String result = s.toUpperCase(); return result; } Lambda expressions in Java are always tied to a specific functional interface type.
🌐
Tutorialspoint
tutorialspoint.com › java › java-lambda-expressions.htm
Java - Lambda Expressions
Using lambda expression, we've created four different implementations of MathOperation operate method to add,subtract,multiply and divide two integers and get the relative result.
🌐
InfoWorld
infoworld.com › home › blogs › java 101: learn java
Get started with lambda expressions in Java | InfoWorld
November 7, 2019 - The first example’s expression-based lambda body doesn’t have to be placed between braces. The second example converts the expression-based body to a statement-based body, in which return must be specified to return the expression’s value. The final example demonstrates multiple statements ...
🌐
Medium
medium.com › @nagarjun_nagesh › syntax-of-lambda-expressions-b7307f96a203
Syntax of Lambda Expressions. In the previous article, we introduced… | by Nagarjun (Arjun) Nagesh | Medium
February 23, 2024 - In this article, we explored the syntax of lambda expressions in Java, gaining a deep understanding of their various components. We saw how lambda expressions can represent functions with no parameters, one parameter, or multiple parameters. Additionally, we learned how lambda expressions can have multiple statements in their body and return values.
🌐
JavaKing
javaking.com › home › latest › java lambda expressions
Java Lambda Expressions: Syntax and Examples
January 2, 2026 - A lambda expression has three parts: parameters, an arrow, and a body. (parameters) -> expression // or (parameters) -> { statements; }
🌐
Studytonight
studytonight.com › java-8 › java-8-lambda-expression
Java 8 Lambda Expression - Studytonight
In these sample examples, we have variety of lambda expression such as zero argument and single statement, multiple arguments, lambda with return statement, etc. although return statment is optional and it can have multiple statements as well.