How to reduce a limited stream (e.g. an ArrayList) from right in Java?

I would like to convert a list to a self-implemented linked list using reduce. I managed to do that in a reverse order: import java.util.Arrays; import java.util.List; public class Reverse { …

Java 8 convert for loop and summing of values to stream/lambda?

I have some String inputs that I am looping over that I am trying to convert to java 8 stream/lambdas but was having some issues. My boilerplate code looks like this: public static int count(List<…

Java functional programming: create list of object from a different list

I’d like to convert to funcional programming the following method: public static List payroll(List employees) { List payrollEntries = new …

returning early from a method if an Optional is empty

Is there a more functional way to return early from a method if an Optional is empty than this? public boolean validate(Optional obj) { if (obj.isPresent(obj) { var object = obj….

Switching Keys in a Map of Maps

How would you use Java 8 streams to swap keys in this map of maps? Or at least clean up this mess a little bit… Map<Type1, Map> to Map<Type2, Map<Type1, String&…

Map getOrDefault VS getOrUseSupplier

I am starting to learn lambdas and i do not understand why java Map has: getOrDefault(Object key, V defaultValue) and not(working just the same, but if value is absent, then defaultValue will be …