All Questions
Tagged with java-stream performance
123 questions
5
votes
2
answers
150
views
Why are inner parallel streams faster with new pools than with the commonPool for this scenario?
So I recently ran a benchmark where I compared the performance of nested streams in 3 cases:
Parallel outer stream and sequential inner stream
Parallel outer and inner streams (using parallelStream) -...
0
votes
2
answers
127
views
Is Java stream filter smart enough to ignore unnecessary items in an ordered stream?
Let's say I have the following:
List<Integer> orderedList = Stream.of(5, 4, 0, 2, 1).sorted().toList();
If I apply a filter such as
List<Integer> filteredList = orderedList.stream()....
-1
votes
1
answer
516
views
Improve response time Java / Stream / filter
I am doing a comparison between two lists of objects using streams (filter/anyMatch). The size of the two lists can be up to a million objects.
I ran a test with the code below. Often the size of the ...
1
vote
1
answer
102
views
Performance impact of Java Streams in Matrix traversal
I have two versions of some code to diagonally traverse an MxN matrix. Apparently, even with the same (bad) traversal logic the version which uses Java Streams run 5x slower that the one which doesn't....
0
votes
1
answer
408
views
How java stream works with immutable collections under the box
Let's looka at the snippet:
List<Integer> numbers = IntStream.range(0, 100_000_000)
.boxed().collect(Collectors.toList());
List<String> res = numbers.stream()
.map(num ->...
2
votes
0
answers
152
views
Why is the following block not thread safe?
We have a Spring Boot application where we fetch data from a database and keep it in a concurrent Hashmap tempMap. Then we use it to fetch details based on the incoming keys. But keys are in the form ...
0
votes
1
answer
60
views
Nested for loops inside a parallel for loops gives incorrect results
I am iterating the foreach loop using parallelStream but inside i have a list of nested for loops.
During iteration its giving incorrect result each time with different value.
I really needs this ...
0
votes
0
answers
161
views
Flat and partition list of a list efficiently
I have a piece of code as follows and the idea is basically to process a fixed amount of items/ids each time based on LIMIT:
List<Integer> employeeId = new ArrayList<>();
for(...
1
vote
1
answer
874
views
java11 stream split n of list chunk as arguments
Let's say I have this (Spring boot) code:
List<User> userList = userService.selectAll(); <-- this returns 1,000,000 rows
customerService.saveBulk(userList).get();
I want to split the list ...
1
vote
4
answers
2k
views
Find Duplicated Elements in a List of Integer without using distinct() method
Recently, I've been asked this question during an Interview :
How to find the Duplicate Elements in a List of Integer without
using java Stream's distinct() method ?
This should be done by Java's ...
-1
votes
1
answer
68
views
Different ways of limiting the sequential ordered Stream
Since java 11 there are several ways to limit sequential ordered Stream:
Stream.iterate(0, v -> v + 1).limit(size)
Stream.iterate(0, v -> v < size, v -> v + 1)
Stream.iterate(0, v -> v ...
1
vote
1
answer
97
views
The curious case of the Java Integer Array streaming performance [duplicate]
Here is a new attempt to present that curious difference in performance in the use of IntStream and reduce to do a computation on an integer array.
My question wasn't understood as legitimate. I was ...
1
vote
3
answers
104
views
How can I map all words in the description of a Film to all films' names that contain the word in their description fast?
I have a List<Films> films, where each film has int id and String description.
My task is to map each word from all the descriptions to all films names that contain the word in the description, ...
1
vote
1
answer
281
views
regex verification of two strings in stream
I have 2 Lists,
Is a List of Strings called tablerows.
Is a List of Objects, which each contain a list of String Values (among other things)
I am trying to iterate over them via streams as follows:
...
0
votes
4
answers
5k
views
Conversion of Map<String, String> to List of Objects
Below is what I am trying to achieve.
"timezones": [
{
"name" : "America/New_York",
"label" : "US Eastern Time"
},
{
...