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
🌐
GeeksforGeeks
geeksforgeeks.org › java › lambda-expressions-java-8
Java Lambda Expressions - GeeksforGeeks
@FunctionalInterface interface ... { // Using lambda expressions to define the operations Functional add = (a, b) -> a + b; Functional multiply = (a, b) -> a * b; // Using the operations System.out.println(add.operation(6, ...
Published   3 weeks ago
🌐
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); } } }
🌐
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 = <strong>(x) -> {</strong> // Lambda Expression with multiple lines x = "Jai " + x; System.out.println(x); return x; }; emp.displayName("Adithya"); } }
🌐
W3Schools
w3schools.com › java › java_lambda.asp
Java Lambda Expressions
Simple expressions must return a value immediately. They cannot contain multiple statements, such as loops or if conditions. To do more complex work, use a code block with curly braces. If the lambda should return a value, use the return keyword: (parameter1, parameter2) -> { // code block return result; } Lambdas are often passed as arguments to methods. For example, you can use a lambda in the forEach() method of an ArrayList: import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); numbers.add(5); numbers.add(9); numbers.add(8); numbers.add(1); numbers.forEach((n) -> { System.out.println(n); }); } } Try it Yourself » ·
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
In the JavaFX example HelloWorld.java (discussed in the previous section Anonymous Classes), you can replace the highlighted anonymous class with a lambda expression in this statement:
🌐
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.
🌐
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.
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java › lambda-expressions.html
Java Lambda Expressions
Java lambda expressions can only be used where the type they are matched against is a single method interface. In the example above, a lambda expression is used as parameter where the parameter type was the StateChangeListener interface. This ...
🌐
Tutorialspoint
tutorialspoint.com › java › java-lambda-expressions.htm
Java - Lambda Expressions
In this example, we've one functional interface GreetingService with a method sayMessage, which we've used to print a message to the console. Now in Java Tester class, we've one final class field salutation having a value "Hello!
🌐
Programiz
programiz.com › java-programming › lambda-expression
Java Lambda Expressions (With Examples)
Note: For the block body, you can have a return statement if the body returns a value. However, the expression body does not require a return statement. Let's write a Java program that returns the value of Pi using the lambda expression.
🌐
Scaler
scaler.com › home › topics › java › lambda expression in java
Lambda Expression in Java | Scaler Topics
May 4, 2023 - When a lambda expression comprises multiple statements, you must use the return keyword. ... To run the thread, you can use a lambda expression. In the following example, we use a lambda expression in Java to implement the run method.
🌐
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 ...
🌐
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
🌐
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.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › lambda expressions in java
Java 8 Lambda Expression (with Examples)
October 1, 2022 - Multiple parameters are enclosed in mandatory parentheses and separated by commas. Empty parentheses are used to represent an empty set of parameters. ... When there is a single parameter, if its type is inferred, it is not mandatory to use parentheses. ... A lambda expression cannot have a throws clause.
🌐
Medium
slycreator.medium.com › deep-dive-into-lambda-expressions-in-java-c74c12910162
Deep Dive into Lambda Expressions in Java | by Sylvester Amaechi | Medium
April 15, 2023 - ... (x, y) -> { int sum = x + y; return sum; } is a lambda expression with a block body that returns the sum of the input. Lambda expressions work with functional interfaces, which are interfaces that have a single abstract method.
🌐
Baeldung
baeldung.com › home › java › lambda expressions and functional interfaces: tips and best practices
Lambda Expressions and Functional Interfaces: Tips and Best Practices | Baeldung
December 16, 2023 - Braces and return statements are optional in one-line lambda bodies. This means that they can be omitted for clarity and conciseness. ... Very often, even in our previous examples, lambda expressions just call methods which are already implemented elsewhere. In this situation, it is very useful to use another Java ...
🌐
Hero Vired
herovired.com › learning-hub › topics › lambda-expression-in-java
Java Lambda Expressions: Use Cases and Examples - Hero Vired
A Java lambda expression contains only one statement, so we can avoid using the return keyword. However, when we use a lambda expression to compress multiple statements, we must use the return keyword.