What you are doing may be the simplest way, provided your stream stays sequential—otherwise you will have to put a call to sequential() before forEach.

The reason the call to sequential() is necessary is that the code as it stands (forEach(targetLongList::add)) would be racy if the stream was parallel. Even then, it will not achieve the effect intended, as forEach is explicitly nondeterministic—even in a sequential stream the order of element processing is not guaranteed. You would have to use forEachOrdered to ensure correct ordering. The intention of the Stream API designers is that you will use collector in this situation, as below:

targetLongList = sourceLongList.stream()
    .filter(l -> l > 100)
    .collect(Collectors.toList());
Answer from Maurice Naftalin on Stack Overflow
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java collect stream to list (with examples)
Java Collect Stream to List (with Examples)
April 29, 2024 - There are primarily three ways to collect stream items into a list. Let’s compare them. The toList() method has been added in Java 16.
Discussions

Why would the JDK Stream.toList() instantiate multiple lists?

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

More on reddit.com
🌐 r/javahelp
3
2
August 23, 2023
Converting a generic list to a list of strings using Java 8 Stream API
Hey everyone! I’m trying to get my head around the Stream API in Java 8. I want to make a simple list of strings from a property in my objects. Here’s what I’ve got so far: class Person { String firstName; int y… More on community.latenode.com
🌐 community.latenode.com
0
0
April 23, 2025
[Java 8] Help converting a nested list of objects into a map using lambdas/streams
This is actually pretty straightforward as far as streams go. The methods you'll want to use are Stream.flatMap and Stream.collect with Collectors.groupingBy. More on reddit.com
🌐 r/learnprogramming
2
1
June 28, 2018
Stream::toList() is weird
You need to specify the target type of the map function, like this: List as = source.stream() .map(s -> new B()) .toList(); Example: https://godbolt.org/z/Yh5WY656d This is because the signature of the map function is Stream map​(Function mapper) so the type of the Stream is determined only from the resolution of R, which get determined from the type of the mapper, and the mapper in your example says that R = B. Edit: Delete some stupid suggestion. More on reddit.com
🌐 r/java
37
24
June 8, 2021
🌐
Baeldung
baeldung.com › home › java › java list › create list of object from another type using java
Create List of Object From Another Type Using Java | Baeldung
March 7, 2025 - In this article, we’ve explored three approaches to creating a list of objects of a different type based on a given list. Through the examples, we learned that the Stream API enhances the productivity and readability of code when working with lists in Java.
🌐
Baeldung
baeldung.com › home › java › java streams › collecting stream elements into a list in java
Collecting Stream Elements into a List in Java | Baeldung
December 3, 2025 - However, there have been change requests for a method to get a List directly from a Stream instance. With the Java 16 release, we can now invoke toList(), a new method directly on the Stream, to get the List.
🌐
Stackify
stackify.com › streams-guide-java-8
A Guide to Java Streams in Java 8 - Stackify
September 4, 2024 - Streams are not data structures but tools for performing operations like map-reduce transformations on collections. This functionality—java.util.stream—supports functional-style operations on streams of elements.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › stream-in-java
Stream In Java - GeeksforGeeks
Below is the syntax given for declaring a Java Stream. ... A Stream is not a data structure; it just takes input from Collections, Arrays or I/O channels. Streams do not modify the original data; they only produce results using their methods. Intermediate operations (like filter, map, etc.) are lazy and return another Stream, so you can chain them together.
Published   1 week ago
🌐
Medium
medium.com › javarevisited › stream-tolist-and-other-converter-methods-ive-wanted-since-java-2-c620500cb7ab
Stream.toList() and other converter methods I’ve wanted since Java 2 | by Donald Raab | Javarevisited | Medium
January 28, 2021 - If we need another converter method, we can use collect and Collectors for other collection types. This will lead to an unfortunate asymmetry in the Stream API usage. The method toList will be very fluent, whereas using Collectors for other types is less so. Naming is important. Naming something well is difficult. List is a mutable interface.
🌐
Medium
medium.com › pelligent › java-streams-1d22b1861a18
Everything about Java Streams put together | by Vishal | Pelligent Tech Blog | Medium
February 12, 2023 - That gives us a stream of numbers starting from 5, incremented by 1. limit() helps to limit the stream up to 10. i.e. a stream from 5 to 14. Stream.iterate(0, n -> n + 1) .skip(5) .limit(10) .forEach(System.out::println); One thing that significantly improves Java streams is the ability to evaluate operations lazily.
🌐
Java67
java67.com › 2020 › 04 › how-to-get-list-or-set-from-stream-in-java8.html
How to Convert Stream to List, Set, and Collection in Java 8? Example Tutorial | Java67
If you have worked with Stream ... java.uti.Collection interface, unfortunately, Stream class doesn't have a method to convert a Stream back to List or Set or any other data structure in Java....
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-get-arraylist-from-stream-in-java-8
How to Get ArrayList from Stream in Java 8? - GeeksforGeeks
July 17, 2024 - Given a Stream, the task is to ... ['G', 'e', 'e', 'k', 's'] ... Get the Stream to be converted. Collect the stream as List using collect() and Collectors.toList() methods....
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-stream-collect-method-examples
Java Stream collect() Method Examples | DigitalOcean
August 3, 2022 - Love Java, Python, Unix and related technologies. Follow my X @PankajWebDev ... While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial. ... 3. Stream collect() to Map List numbers = List.of(1, 2, 3, 4, 5, 6); Map mapOddNumbers = numbers.stream() …
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › Stream.html
Stream (Java Platform SE 8 )
2 weeks ago - When executed in parallel, multiple intermediate results may be instantiated, populated, and merged so as to maintain isolation of mutable data structures. Therefore, even when executed in parallel with non-thread-safe data structures (such as ArrayList), no additional synchronization is needed for a parallel reduction. ... Map<String, List<Person>> peopleByCity = personStream.collect(Collectors.groupingBy(Person::getCity));
🌐
Latenode
community.latenode.com › other questions › api
Converting a generic list to a list of strings using Java 8 Stream API - API - Latenode Official Community
April 23, 2025 - Hey everyone! I’m trying to get my head around the Stream API in Java 8. I want to make a simple list of strings from a property in my objects. Here’s what I’ve got so far: class Person { String firstName; int yearOfBirth; } List peopleList = dataProvider.getPersons(); List person.firstName).collect(Collectors.toList()); But it’s not working right.
🌐
Medium
medium.com › @AlexanderObregon › javas-collectors-tolist-method-explained-0e90e5d90dcb
Java’s Collectors.toList() Method Explained | Medium
August 23, 2024 - Often, filtering and mapping are used together in a stream pipeline to achieve more complex data transformations. For example, let’s say you have a list of product prices in various currencies, and you want to filter out prices below a certain threshold and convert the remaining prices to a different currency: import java.util.List; import java.util.stream.Collectors; import java.util.stream.DoubleStream; public class PriceConversionExample { public static void main(String[] args) { double conversionRate = 0.85; // Conversion rate to another currency List<Double> convertedPrices = DoubleStream.of(100.0, 50.0, 250.0, 75.0, 300.0) .filter(price -> price > 100.0) .map(price -> price * conversionRate) .boxed() .collect(Collectors.toList()); System.out.println(convertedPrices); // Output: [212.5, 255.0] } }
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.streams › to-list.html
toList | Core API – Kotlin Programming Language
import java.util.stream.* import kotlin.streams.* fun main() { //sampleStart val stringStream: Stream<String> = Stream.of("Lion", "Leopard", "Jaguar", "Tiger") val stringList: List<String> = stringStream.toList() println(stringList) // [Lion, Leopard, Jaguar, Tiger] //sampleEnd }
🌐
GeeksforGeeks
geeksforgeeks.org › java › program-to-convert-list-to-stream-in-java
Program to Convert List to Stream in Java - GeeksforGeeks
July 11, 2025 - Convert Stream into List using List.stream() method. ... // Java Program to convert // List to Stream in Java 8 import java.util.*; import java.util.stream.*; import java.util.function.Function; class GFG { // Generic function to convert a list ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-8-stream-tutorial
Java 8 Stream Tutorial - GeeksforGeeks
September 12, 2025 - From an Array: Use Arrays.stream(array) to convert an array into a stream. Using Stream.of(): Create a stream from a fixed set of values using Stream.of(). Infinite Stream: Generate an unbounded sequence using Stream.iterate() or Stream.generate() ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › Collectors.html
Collectors (Java Platform SE 8 )
2 weeks ago - Java™ Platform Standard Ed. 8 ... Implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc. The following are examples of using the predefined collectors to perform common mutable reduction tasks: // Accumulate names into a List List<String> list = people.stream...