๐ŸŒ
Jfokus
jfokus.se โ€บ jfokus17 โ€บ preso โ€บ Java-SE-8-best-practices.pdf pdf
Java SE 8 Best Practices
Jfokus is Swedens largest developer conference. Stockholm Waterfront Congress Centre, 6-8 February 2017
๐ŸŒ
JRebel
jrebel.com โ€บ blog โ€บ java-8-cheat-sheet
Java 8 Cheat Sheet and Best Practices | JRebel
Download our Java 8 Best Practices Cheat Sheet for a one page reference to default methods, lambdas, containers, and coding best practices in Java 8.
Discussions

Java 8 Best Practices Cheat Sheet
I'm more of a C# guy but have to do some work in Java. In the "Lambda" section, they separated each lambda part per line but didn't start with the "." but rather ended with it. Is that standard Java practice? i.e.: new ArrayList().stream(). peek(e -> System.out.println(e)). map(e -> e.hashCode()) rather than: new ArrayList().stream() .peek(e -> System.out.println(e)) .map(e -> e.hashCode()) To me, the second is so much clearer that you are chaining. EDIT: Removed extra "." in second example. More on reddit.com
๐ŸŒ r/java
22
59
January 25, 2018
collections - What is the best practice for managing Java 8 streams with multiple results - Stack Overflow
How to process forEach in Java 8 using streams when I want to have multiple results from the iteration. Of course calling List.add method in stream forEach operation is not an option... How would you More on stackoverflow.com
๐ŸŒ stackoverflow.com
best practices: no-op in java ?
I don't see a problem with a nop method. I tend to use assert statements for the same purpose, a-la "assert true" The cool thing about assert statements is that they don't actually run in production code unless the "-ea" flag is provided to the java command. More on reddit.com
๐ŸŒ r/java
40
15
April 16, 2013
Java 8 Best Practices Cheat Sheet

The article: Hi there, do you like trains? 

Me:???

More on reddit.com
๐ŸŒ r/programming
3
0
January 27, 2018
๐ŸŒ
Medium
medium.com โ€บ @amoghdeshpande100 โ€บ java-8-best-practices-with-real-time-scenarios-e855d287df27
Java 8 best practices with real time scenarios | by Amoghdeshpande | Medium
May 25, 2025 - Best Practice: Default methods in interfaces allow you to add new functionalities without breaking existing implementations.
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ java โ€บ java 8 top tips
Java 8 Top Tips
July 26, 2016 - As developers become more familiar with Java 8 code, weโ€™ll know what to expect when using interfaces like Supplier and Consumer, and creating a home-grown ErrorMessageCreator (for example) could be confusing, and wasteful.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Java 8 best practices by Stephen Colebourne - YouTube
The Java 8 release takes Java to a whole new level. Learning the new features is just the first step. The real question is how to make best use of them. Ther...
Published ย  June 16, 2016
๐ŸŒ
JAX London
jaxlondon.com โ€บ wp-content โ€บ uploads โ€บ 2015 โ€บ 10 โ€บ Java-8-best-practices-Stephen-Colebourne.pdf pdf
Jaxlondon
JAX London is a five-day conference for Enterprise Engineering in the Age of AI | September 28 - October 2, 2026 |
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-8-features-with-examples
Java 8 Features with Examples | DigitalOcean
August 3, 2022 - Functional interfaces are a new concept introduced in Java 8. An interface with exactly one abstract method becomes a Functional Interface. We donโ€™t need to use @FunctionalInterface annotation to mark an interface as a Functional Interface. @FunctionalInterface annotation is a facility to avoid the accidental addition of abstract methods in the functional interfaces. You can think of it like @Override annotation and itโ€™s best practice ...
Find elsewhere
๐ŸŒ
JavaTechOnline
javatechonline.com โ€บ home โ€บ java coding best practices and standards
Java Coding Best Practices And Standards - JavaTechOnline
April 21, 2024 - 1) Neglecting the NullPointerException 2) Instantiating Objects Inside Loops 3) Using the โ€˜newโ€™ keyword while creating String 4) Forgetting to free Resources after use 5) Writing Code that causes Memory Leaks 6) Unreasonable Garbage Allocation ...
๐ŸŒ
Saltmarch
saltmarch.com โ€บ insight โ€บ 8-essential-secure-java-8-coding-practices
8 Essential Secure Java 8 Coding Practices
Throughout our journey, we've learned to validate inputs, embrace the least privilege principle, implement defense in depth, fail securely, prevent SQL injection and cross-site scripting, use libraries securely, and leverage security testing tools.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-8-features-tutorial
Java 8 Features - Complete Tutorial - GeeksforGeeks
September 23, 2025 - Stream API is introduced in Java 8 and is used to process collections of objects with the functional style of coding using the lambda expression.
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ java 8 best practices cheat sheet
r/java on Reddit: Java 8 Best Practices Cheat Sheet
January 25, 2018 - Best practices cheatsheet. Uses lowercase-l as an identifier in a code example. ... Cheat sheet repository for beginners. ... High complexity, low quality, legacy Java code.
Top answer
1 of 3
4

The way to do things like this with streams is to use a custom collector. Suppose we define the following class:

public class Results {
    private final List<WebsiteModel> additionalWebsitesList = new ArrayList<>();
    private final List<AreaModel> areaModels = new ArrayList<>();
    private final StringBuilder additionalWebsitesCsv = new StringBuilder();

    public void accumulate(WebsiteModel websiteModel) {
        additionalWebsitesList.add(websiteModel);
        areaModels.addAll(websiteModel.getAreas());
        additionalWebsitesCsv.append(websiteModel.getId());
    }

    public void combine(Results another) {
        additionalWebsitesList.addAll(another.additionalWebsitesList);
        areaModels.addAll(another.areaModels);
        additionalWebsitesCsv.append(another.additionalWebsitesCsv);
    }

    public List<WebsiteModel> getAdditionalWebsitesList() {
        return additionalWebsitesList;
    }

    public List<AreaModel> getAreaModels() {
        return areaModels;
    }

    public String getAdditionalWebsitesCsv() {
        return additionalWebsitesCsv.toString();
    }
}

With this Results class in place, you're ready to collect the results:

Results results = additionalWebsites.stream()
    .map(this::getWebsiteModel)
    .collect(Results::new, Results::accumulate, Results::combine);

This uses the Stream.collect method. The first argument is a Supplier that creates the mutable object into which elements of the stream are to be accumulated via the accumulator provided in the second argument. The third argument is a merger that will only be used to combine partial results if the stream is parallel.

2 of 3
3

What is the best practice for managing Java 8 streams with multiple results

Of course calling List.add method in stream forEach operation is not an option.

The best practice is not forcing you to use streams as the use case is not appropriate.
The Stream interface javadoc describes itself as :

A sequence of elements supporting sequential and parallel aggregate operations.

Stream operations return themselves a sequence of typed elements.
So Stream collects will return finally a single kind of thing based on the type of the sequence of elements : unitary or a collection of.
We could for example collect a Foo, a List of Foo, a Map of Foo indexed by Integer keys, and so for...
Stream collects are not designed to collect different custom things such as a List of Foo + a List of Bar + the count of Bar + Foo.

As @Eugene underlined, Streams also provide a way to get IntSummaryStatistics that is a set of things : common aggregates that are minimum, maximum, sum, and average. But should we not consider that it collects finally a single thing : statistics ?

So you have three ways :

  • putting aside Stream for your use case and keeping the for loop.

  • using multiple streams : one stream by custom thing that you want to collect.

  • using a single stream with a custom collector.

I would not use the second way in any case as it will produce a less readable and straight code that your actual.

About the last way (custom collector) illustrated by the Federico Peralta Schaffner answer. It is straighter and it allows to benefit from stream parallelism. So it is an option to consider.
But it also requires more boiler plate code and has more reading indirection to understand the actual logic.
So I think that I would introduce a custom collector only in two cases :

  • the collector is reused.
  • we want to benefit from the stream parallelism and we have a very important number of elements to process in (Federico Peralta Schaffner explains it very well in its comment, thanks).

And in any other cases, I would keep the for loop.

๐ŸŒ
Google
google.github.io โ€บ styleguide โ€บ javaguide.html
Google Java Style Guide
Terminology Note: block-like construct refers to the body of a class, method, constructor, or switch. Note that, by Section 4.8.3.1 on array initializers, any array initializer may optionally be treated as if it were a block-like construct.
๐ŸŒ
Medium
cinish.medium.com โ€บ java-8-best-practices-5a4b5b4cd313
Java 8:Best practices. What is target typing in the context ofโ€ฆ | by Learn | Medium
January 22, 2018 - Java 8:Best practices What is target typing in the context of Lambdas? Context determines the type of the lambdas as in the type is implicitly inferred. If you have an array of Strings and you supply โ€ฆ
๐ŸŒ
TatvaSoft
tatvasoft.com โ€บ home โ€บ java best practices for developers
Java Best Practices for Developers - TatvaSoft Blog
February 18, 2026 - Another Java best practice is to use StringBuffer or StringBuilder for String concatenation. Since String Object is immutable in Java, whenever we do String manipulation like concatenation, substring, etc., it generates a new string and discards ...
๐ŸŒ
Varniktech
varniktech.com โ€บ home โ€บ selenium java โ€บ java coding best practices
Top Java Coding Best Practices 2025
July 24, 2025 - Understand Java 8 and Java 11 features used in the industry ยท Get familiar with multithreading, file handling, and APIs ยท Build real projects that show your practical skills ... These tools are must-haves for most Java job roles today. ... These are not just demo projects. They are designed to test and reinforce best ...
๐ŸŒ
JRebel
jrebel.com โ€บ resources โ€บ java-8-best-practices
Java 8 Best Practices | JRebel & XRebel by Perforce
November 15, 2019 - Our Java 8 Best Practices Cheat Sheet includes information on default methods, Lambdas and java.util.Optional. Download it today!
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ java 8 features
Java 8 Features with Examples
November 11, 2025 - The Optional feature of Java 8 is used to avoid NullPointerException, but instead of using it for parameters or class fields, it is best recommended to use it in the method return type. Instead of using callbacks or manual thread handling, it is recommended to use chained CompletableFutures for better asynchronous tasks. Following these best practices helps you write cleaner, safer, and more maintainable code using Java 8 features.