Distinct and Concat Methods

Java-Distinct and Concat Methods

Distinct and Concat Methods The distinct( ) method returns a stream that yields elements from the original stream, in the same order, except that duplicates are suppressed. The stream must obviously remember the elements that it has already seen. You can concatenate two streams with the static concat( ) method of the Stream class. Program … Read more…

Stream Creating Methods

Java-Stream Creating Methods

Stream Creating Methods You can turn any collection into a stream with the stream method of the Collection interface, but if you have an array, use the static Stream.of method instead. This method has three forms: The second form has a varargs parameter, so you can construct a stream from any number of arguments. Using Arrays.stream( … Read more…

Primitive Type Streams

Java-Primitive Type Streams

Primitive Type Streams Because Stream operates on object references, it can’t operate directly on primitive types, such as double, float, long, short, char, byte, and boolean. To handle primitive type streams, the stream library has specialized types IntStream, LongStream, and DoubleStream that store primitive values directly, without using wrappers. If you want to store int, use … Read more…

Flattening Streams

Java-Flattening Streams

Flattening Streams When you use map( ), a function is applied to each element, and the result is a new stream with the results. Now, suppose you have a function that returns not just one value but a stream of values: Suppose you map the stringToInStream method on a Stream of Strings: Each values are printed … Read more…

Mapping

Java-Mapping

Mapping Most often it is useful to map the elements of one stream to another. For example, you might want to apply some transformation to the elements in a stream. To do this, you could map the transformed elements to a new stream. Because mapping operations are quite common, the stream API provides built-in support for … Read more…

Parallel Streams

Java-Parallel Streams

Parallel programming Parallel programming is an important trend in software development in recent years. Parallel programming is the name commonly given to the techniques that take advantage of computers that contain two or more processors (multicore). Today, mostly we all are using multi core computers, such as Intel Core i7,AMD Ryzen 9. The advantage that multiprocessor environments offer … Read more…