Building an infinite stream in java 8

Introduction In java, we can convert a specific set into a stream, so in some cases, such as in a test environment, we need to construct a stream with a certain number of elements, how do we need to handle it? Here we can construct an unlimited stream and then call the limit method to limit the number returned. Basic use Let’s start with an example of using Stream.iterate to create an infinite Stream.

Customizing parallelStream's thread pool

Introduction By default, ForkJoinPool creates a thread for each processor, and parallelStream will use this shared thread pool to submit tasks if not specified. So how do we handle a specific situation where we want to use a custom ForkJoinPool? Common operations If we want to do an addition from 1 to 1000, we can use parallel stream like this. List<Integer> integerList= IntStream.range(1,1000).boxed().collect(Collectors.toList()); ForkJoinPool customThreadPool = new ForkJoinPool(4); Integer total= integerList.

Java stream common operations on streams

Introduction As we all know, starting from Java8, jdk has added a new Stream class to complement the collection class. Stream provides a higher-order abstraction of Java collection operations and expressions using an intuitive way similar to querying data from a database with SQL statements. This style treats the collection of elements to be processed as a stream, which travels through the pipeline and can be processed at the nodes of the pipeline, such as filtering, sorting, aggregating, etc.