Category "java-stream"

Collect both matching and non-matching in one stream processing?

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

How to check if list has more then 3 elements using Java8

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

Java stream. Sum two fields in a stream of objects

I have something like this: Integer totalIncome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getIncome()).sum(); Integer total

What is the fastest way to iterate on a stream in Java 8?

If I have a collection and I want to iterate over a filtered stream then I could do either of the following (and many more obtuse options): for(item in collect

Why is a parallel stream slower than a sequential stream?

I have two functions solving the same problem. The first uses a sequential stream, and the second uses a parallel stream. public static int digitalRoot(int n)

How to remove Duplicated elements from a List based on Two properties using Java 8 streams?

I'm trying to figure out how to write a stream in Java 8 that removes duplicate records based on a property and a condition, for example: +----+----------------

How to write a method that takes in a List of Integer, Float, Double and calculate the average?

I am trying to write a method that takes in a list of numeric values - eg List<Integer>, List<Float>, List<Double> etc - and give me the avera

How to write a method that takes in a List of Integer, Float, Double and calculate the average?

I am trying to write a method that takes in a list of numeric values - eg List<Integer>, List<Float>, List<Double> etc - and give me the avera

Merge Map<String, List<String> Java 8 Stream

I would like to merge two Map with JAVA 8 Stream: Map<String, List<String>> mapGlobal = new HashMap<String, List<String>>(); Map<Str

How to find the tag Value in the dynamic JSON-Object with Java 8

I have JSON-object which has a dynamic key inside it. I need to get a specific value mapped to this dynamic Key. For example: value "10.00" will be returned for

Java Stream: divide into two lists by boolean predicate

I have a list of employees. They have isActive boolean field. I would like to divide employees into two lists: activeEmployees and formerEmployees. Is it possib

Java 8 Stream - .max() with duplicates

So I have a collection of objects that have a step variable that can be 1 - 4. public class MyClass { private Long step; //other variables, getters, s

How to check if exists any duplicate in Java 8 Streams?

In java 8, what's the best way to check if a List contains any duplicate? My idea was something like: list.size() != list.stream().distinct().count() Is it

How to compare the elements of an ArrayList with every element of another ArrayList using Stream API of Java 8?

I have two Sorted ArrayList of same size, namely team_A & team_B, in which comparing every element of team_A with team_B to find the powerDiff > 0. After