All Questions
77 questions
3
votes
1
answer
115
views
In Java, replace for loop with condition with lambdas [closed]
I want to replace a for loop with a break/return condition inside with a lambda.
I think I have a good replacement, but I want ...
2
votes
2
answers
130
views
Find all line numbers of prefix duplicates with streams
All line indices of lines from a text that begin with the same line prefix should be found. The prefixes and the corresponding line numbers should be returned. Streams and lambdas should be used as ...
3
votes
2
answers
200
views
Add offset to all filenames
From all the files in a directory, the method shiftFilenamesOffset is to increment the numeric part (int) of the alphanumeric filename by offset each time, and ...
4
votes
0
answers
100
views
Print columns of text without hard coding the width (attempt 5)
If you'd like to print this:
...
0
votes
3
answers
295
views
Print columns of text without hard coding the width (attempt 4)
If you'd like to print this:
One Two Three Four
1 2 3 4
using this:
...
4
votes
1
answer
295
views
Print columns of text without hard coding the width (attempt 2)
If you'd like to print this:
One Two Three Four
1 2 3 4
using this:
...
0
votes
1
answer
587
views
Compute the goals scored by football teams in their matches in a season, from json data
Please look at the Java Stream methods in the for each loop.
This method totals the score for when the your desired team is playing during the football season - input param teamKey - it is either ...
3
votes
4
answers
189
views
Print sums of pairs from 1 to 10
This takes the sum of pairs of numbers from 1 to 10 and outputs the sum, the original numbers, and some connecting text. Output:
intArray.length 10
{Sum of + 1 and 2 =3, Sum of + 3 and 4 =7, Sum of +...
0
votes
1
answer
105
views
Avoiding Java stream repeated code using lambdas
This is the code for adding addon product to carts. Suppose the cart has a cake so a candle would be an addon. I see this ...
2
votes
2
answers
178
views
Radio with channels
Realize the Radio and Channel classes that represent radio and a radio station. The radio class offers an argumentless constructor and the following methods:
addChannel: stores and returns a new ...
1
vote
1
answer
1k
views
How to make this nested lambda expression readable?
This is the code that joins the list with another one. Also makes use of a static utility to makes use of hashmap for id and name.
I've added null checks to safeguard the code with NPE.
The key ...
0
votes
1
answer
206
views
Correct use of Serializable with lambda functions
I'm practicing saving and reading serializable objects when a friend told me serializable objects have no use in real life, that I'd better focus on JSON or XML to serialize my objects when I came ...
2
votes
1
answer
81
views
Building a list from the Catresian square of an array
The code generates a list containing all possible combinations of the items of an array. Every triplet of items contains two operands and the third item containing ...
1
vote
1
answer
51
views
Concise and exception-prone method for running method on component
I have a list of Components. When an actor is connected, I want to run onActorConnected on each component. However, if a ...
4
votes
1
answer
454
views
Java - Functional interface for merging two lists
Hello dear colleagues.
As an exercise for Java streams, I've written simple program, which scrapes links to references from a news portal. Basically, I wanted to find out, which portals are the most ...