<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Streams on Abdelbaki Ben Elhaj Slimene</title><link>https://bakic.github.io/tags/streams/</link><description>Recent content in Streams on Abdelbaki Ben Elhaj Slimene</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sat, 12 Aug 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://bakic.github.io/tags/streams/index.xml" rel="self" type="application/rss+xml"/><item><title>The Most Used Stream Operations in Java With Examples</title><link>https://bakic.github.io/posts/the-most-used-stream-operations-in-java-with-examples/</link><pubDate>Sat, 12 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/the-most-used-stream-operations-in-java-with-examples/</guid><description>&lt;p&gt;Stream operations were introduced in Java 8 and they allow you to manipulate collections of data in a concise and functional way. A stream can be seen as a sequence of elements that you can perform various operations on, such as filtering, mapping, or reducing.&lt;/p&gt;&#10;&lt;p&gt;This article serves as a comprehensive guide to the most commonly used stream operations, with clear explanations and practical examples.&lt;/p&gt;&#10;&lt;h2 id="setting-up-and-creating-streams"&gt;Setting up and Creating Streams&lt;/h2&gt;&#10;&lt;p&gt;To work with stream operations, you need to create a stream first. Streams can be created from various data sources, including collections, arrays, or input/output channels. For example, to create a stream from a list, you can use the &lt;code&gt;stream()&lt;/code&gt; method:&lt;/p&gt;</description></item><item><title>A Deep Dive into the flatMap Operation of the Stream API in Java with Examples</title><link>https://bakic.github.io/posts/flatmap-stream-api-java/</link><pubDate>Thu, 10 Aug 2023 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/flatmap-stream-api-java/</guid><description>&lt;p&gt;The &lt;code&gt;flatMap&lt;/code&gt; operation is an intermediate operation provided by the Stream API, which allows you to transform each element of a stream into zero or more elements and then flatten the resulting elements into a single stream. It&amp;rsquo;s useful to use with nested data structures, such as lists within lists and effectively &amp;ldquo;flattening&amp;rdquo; them into a more manageable format.&lt;/p&gt;&#10;&lt;p&gt;In this article we are going to explain how this operation works internally and give some examples.&lt;/p&gt;</description></item><item><title>Difference between Map and FlatMap in Java</title><link>https://bakic.github.io/posts/difference-between-map-and-flatmap-in-java/</link><pubDate>Thu, 18 Feb 2021 00:00:00 +0000</pubDate><guid>https://bakic.github.io/posts/difference-between-map-and-flatmap-in-java/</guid><description>&lt;p&gt;&lt;img src="image-1.jpg" alt="Photo by Clément Hélardot on Unsplash"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;amp;utm_medium=referral"&gt;Clément Hélardot&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;The Stream API of Java 8 provides two intermediate stream operations used to perform actions on stream elements and return a stream as an output: &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt;. In this article, we are going to take a look at these two methods and explain the difference between them with examples.&lt;/p&gt;&#10;&lt;h2 id="map-function"&gt;Map function&lt;/h2&gt;&#10;&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; function takes a &lt;code&gt;Function&lt;/code&gt; as a parameter and applies it to all the elements of the stream. The result will be a stream of the result of the function applied to each element of the initial stream. There is a &lt;strong&gt;one-to-one&lt;/strong&gt; mapping between the input and the output elements.&lt;/p&gt;</description></item></channel></rss>