Skip to main content

All Questions

1 vote
0 answers
49 views

Why do I need to specify the types of the Map.Entry. Is it because the types of the keys are different? [duplicate]

The following code results in the error: Non-static method cannot be referenced from a static context public static Optional<String> getAuthorWithMostPublishedBooks(){ return books.stream()...
Bruno Almeida's user avatar
0 votes
0 answers
34 views

Java Stream API memory consumption of multiple .filter() in chain [duplicate]

Have a question regarding .filter (or any other non-terminal) methods in Stream API chain (code in the block below is just for example): var s1 = Stream.of(1,2,3,4,5,6,7,8,9); var intemidiate1 = s1....
omelnykov's user avatar
-1 votes
1 answer
158 views

Could Java stream create memory overhead [closed]

What I got from basic principle of Java streams is that it works on immutable objects and does operation and collect (if we collect it as collection) as new immutable objects. Does that means for any ...
mubir's user avatar
  • 895
0 votes
0 answers
113 views

How to use Stream.collect with specific class as suplider

I am a student. You might think I'm overloading the code with this, unnecessarily, but the goal is just to improve the understanding of the collect method. So all these components that I mention are ...
Saerujeji Reebu CHINA's user avatar
-1 votes
1 answer
86 views

Transforming Java POJOs and nested streams(Java 8), with possibility of null inner stream

Say I have following java POJOs class Outer { Config; List<Warning> warnings; } class Config { String configId; String configName; } class Warning { String warningId; String ...
curiousengineer's user avatar
-3 votes
1 answer
75 views

Setting up different Java class fields value by a single value on some counter value [closed]

Setting up different Java class fields value by a single value on some counter value? In a Java class, having similar kind of fields like: public class User { private String user_Id_1; private ...
Kishore_2021's user avatar
1 vote
1 answer
111 views

Grouping by multiple fields and counting using in Java 8

I have a Person table in database and the associated domain class looks like below: public class Person { private String firstName; private String secondName; private String city; ...
Akash Sharma's user avatar
-1 votes
1 answer
146 views

Converting nested loop into idiomatic Java 8 stream operators

The following legacy logic needs to be converted into Java 8 functional approach: AchFile dataRoot = unmarshalled.stream().findFirst().get(); List<AchBatch> batches = dataRoot....
Simeon Leyzerzon's user avatar
0 votes
1 answer
65 views

How to use an if statement in a Java stream to avoid a duplicate stream process

Here is my code from the Java MOOC.fi course where I am learning about streams. The code below works but the way I wrote it is quite amateur. I was thinking of somehow integrating an if statement in ...
Bekz's user avatar
  • 3
0 votes
1 answer
55 views

Can't get reducer stream to work in Java. What's wrong with my code?

I want to use a reducer to sum up all the inputs from 'args', then divide by the args length to get the result I'm looking for (just a simple function to learn java). I'm following (as far as I can ...
Mystertea's user avatar
3 votes
3 answers
1k views

Java Stream Methods vs foreach

I have a teammate that did all his stream operations in a foreach execution. I tried to come up with advantages of using the filter, map and to list methods instead. What are other advantages it has ...
Lior Derei's user avatar
0 votes
1 answer
539 views

Getting List of Integers from List of Array of Objects

I have my resultset in List of array of objects. I want to get values in an Integer list using java stream. List<Object[]> to List<Integer> in java8. I was trying to achieve like this....
Prabhash Mishra's user avatar
1 vote
1 answer
320 views

How to declare Comparator using Java 8 syntax?

I have a 2D array of type int i.e [][]intervals Using Java 8 syntax, I can sort like this Arrays.sort(intervals, (int[] o1, int[] o2) -> { if (o1[1] != o2[1]) return o1[1] - o2[1]; return ...
curiousengineer's user avatar
6 votes
3 answers
2k views

Java Stream : How to filter conditionally?

I have the following stream statement with Java Stream and I filter records based on the typeId values as types.getIds().contains(x.getType().getId()): return petRepository.findAll().stream() ...
user avatar
0 votes
1 answer
161 views

Functional Programing; using streams to create a set/ list of objects in java

the object of this specific function is to create a list of (competitor objects ) Using 2 lists containing time and names. note that this is a trail to convert from object oriented to functional ...
mustafa qasmieh's user avatar

15 30 50 per page
1
2 3 4 5
23