I have a fun puzzler. Say I have a list of String values: ["A", "B", "C"] Then I have to query another system for a Map<User, Long> of users with an attr
I want to find a target sum in an array by adding integers until it's reached, then return the indexes which add up to the target by using streams. For example,
I have this piece of code : Map<String, BillingAccount> billingAccountsMap = new HashMap<>(); for (BillingAccount ba : billingAccounts) { if (ba
This is probably very basic, but I am not a Java person. Here is my processing code which simply prints and sleeps: private static void myProcessings(int va
Let's say we have the following method. void some(int id, int... otherIds) { } How can I create a single IntStream with those two arguments?
Suppose we have an excel spreadsheet that looks like: StatusCount FirstName LastName ID 1 Tod Mahones 122145 0 Tod Maho
I get a stream of some custom objects and I would like to create a map Map<Integer, MyObject> with index of each object as key. To give you a simple examp
I'm trying to achieve this using only functional programming constructs (Streams, Collectors, lambda expressions). Let's say list is a String[]: {"Apple", "Sa
I have a class that for which each instance has a unique Id, a name and update date. ID NAME UPDATE DATE 1200 ANNA* 2022-03-01 1300 JONH* 2022-04-01 1200 ANNA*
In the code shown below, p is a predicate of type Predicate<String>. Map<Boolean, List<String>> partitioned = numbers.stream() .collect(Co
I have a list of objects from the database and i want to filter this list using the filter() method of the Stream class. New objects will be added to the databa
I'm trying to filter a List of objects that implements an interface. And I'm trying to create a generic method for all the classes. Something like: interface So
Experimenting with streams I ran into the following behavior which I don't quite understand. I created a parallel stream from an iterator and I noticed that it
I have one string say "Aniruddh" and I want to reverse it using lambdas and streams in Java 8. How can I do it?
Given the following Java 8 Stream: scheduleService.list().stream() .filter(Schedule::getEnabled) .filter(this::runn
I'm getting occasionally ConcurrentModificationException with the following code: public Set<MyObject> getTypes(Set<Type> names) { Set<My
list.parallelStream().forEach(element -> ...); How can I limit the number of parallel threads nowadays? There was a "hack" in the past to set a System prope
Is there a way to collect both matching and not matching elements of stream in one processing? Take this example: final List<Integer> numbers = Arrays.as
I have a method that accepts a list of object. I want to iterate through that list and check if the list has more than 3 elements. If it does, I want to throw e
I have something like this: Integer totalIncome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getIncome()).sum(); Integer total