Skip to main content

All Questions

Filter by
Sorted by
Tagged with
5 votes
6 answers
432 views

Search values by priority in a Stream

I have a simple list of results, and I need to return only one value depending on content, for example: ...
zond's user avatar
  • 151
3 votes
1 answer
110 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 ...
Oscar Besga Panel's user avatar
5 votes
2 answers
161 views

Print the three most occurring chars in Java using streams

The three characters that occurs most in a given string should be printed by using streams/lambdas (functional programming). The order of characters that occur equally often should be preserved. My ...
Tobias Grothe's user avatar
3 votes
1 answer
108 views

Sequentially find the indexes of an element into a collection

Util class to find into a collection the indexes of a given element with multiple occurrences from the first index or relative to a given index. ...
user avatar
2 votes
1 answer
128 views

Stream Partitioner

Discussion I've been trying to increase my knowledge of Java Streams and for practice, I devised up the requirement of partitioning a Stream of values into a ...
Jae Bradley's user avatar
  • 1,875
2 votes
2 answers
473 views

A Union Data Type

Introduction I'm trying to get familiar with functional programming by implementing some functional concepts. One of these concepts that I've attempted to implement below is a ...
Jae Bradley's user avatar
  • 1,875
3 votes
2 answers
443 views

Streaming substrings of a string

Given a (long) string src, generate substrings (up to) len characters long on demand by iterating over ...
Kedar Mhaswade's user avatar
3 votes
2 answers
198 views

Compute variance via functional programming

So I'm supposed to calculate variance based on this forumula through functional programming: $$\sigma^2 = \frac{\sum\limits_{i=0}^{n-1} (X -\mu)^2}{n-1}$$ This is the code that works: ...
Leon's user avatar
  • 133
3 votes
1 answer
658 views

Updates or creates an entity based on if a value is present in an Optional

I need to get car info from a 3rd party web service and persist the data in my application DB. If my DB already has the car, I only update property values that may have changed. Otherwise, I create ...
James's user avatar
  • 289
3 votes
2 answers
5k views

Hackerrank problem: Climbing the Leaderboard (Java)

I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
Mughees Asif's user avatar
3 votes
2 answers
224 views

Creating a new list using a stream

I have a StudentSchedule class that contains schedules of a student, the student may switch between rooms over time. There's no overlap with the date ranges so if a student stops at 2020-01-01 the ...
Archimedes Trajano's user avatar
3 votes
2 answers
162 views

Leap year check in Java (functional style)

I have done the leap year check on https://exercism.io already in a lot of languages. Today I came back to the exercise in Java and was playing around with some maybe more funny ways to do the check. ...
Matthias Wimmer's user avatar
0 votes
1 answer
107 views

Pure methods for updating java objects

I've been reading about pure methods and immutability in Java. I have a current application and want to convert all the methods to pure methods. My app takes payment from users. I first create a ...
Mark's user avatar
  • 221
2 votes
1 answer
318 views

FizzBuzz with Lambda Expressions in Java

I wanted to create a FizzBuzz in Java that is supposed to be open for extension. So the initial problem is the good old, if divisible by 3 print fizz, if divisible by 5 print buzz, if divisible by ...
Koray Tugay's user avatar
  • 1,557
1 vote
3 answers
121 views

Picking from a list of individuals based on their fitness values

I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...
Rafalsky's user avatar

15 30 50 per page