Tag: Streams

Clone a List in Java

In this post, we will see how to clone a List in Java. We need to construct a list containing the elements of the specified list, in the same order as the original list.   Assume there are no mutable objects in the list. i.e. the code can perform a shallow copy.

Flatten Stream of Arrays or Lists in Java using Stream.concat() method

Java 8 Streams can holds different types of data. For example, Stream<T>, Stream<T[]>, Stream<List<T>> – all these are valid streams in Java 8. We have seen in the previous post that flatMap() method can be used for flattening Streams in Java. In this post, we will flatten Stream of Arrays or Lists using Stream.concat() method …

Reverse elements of a Parallel Stream in Java

In this post, we will see how to reverse elements of a parallel Stream in Java. In other words, we’ll create a new Stream which iterates the elements of specified stream in reverse order.