Skip to main content
Share Your Experience: Take the 2024 Developer Survey

All Questions

Filter by
Sorted by
Tagged with
3 votes
1 answer
91 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
147 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
93 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
122 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,845
2 votes
2 answers
442 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,845
3 votes
2 answers
403 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
169 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
642 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
  • 299
3 votes
2 answers
4k 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
207 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
1 vote
0 answers
108 views

Building maps for Dgraph integration tests in Java 8

I want to refactor this in Java to reduce my code duplication. ...
devinbost's user avatar
  • 119
0 votes
1 answer
92 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
1 vote
1 answer
308 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,547
1 vote
3 answers
102 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