Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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) -...
Andorrax's user avatar
  • 125
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()....
Paulo Guedes's user avatar
  • 7,279
-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 ...
YK mar's user avatar
  • 677
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....
Mrinal Shahi's user avatar
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 ->...
Oleg Cherednik's user avatar
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 ...
Zedark's user avatar
  • 21
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 ...
Mohana Priya's user avatar
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(...
Jim's user avatar
  • 4,483
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 ...
jlc488's user avatar
  • 1,061
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 ...
jagdish khetre's user avatar
-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 ...
jwpol's user avatar
  • 1,505
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 ...
Florian F's user avatar
  • 1,377
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, ...
vanderwaal's user avatar
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: ...
Ceress_Sedai's user avatar
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" }, { ...
Rahul's user avatar
  • 603

15 30 50 per page
1
2 3 4 5
9