<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: vikrampawar</title>
    <description>The latest articles on DEV Community by vikrampawar (@vikrampawar).</description>
    <link>https://dev.to/vikrampawar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F109031%2Fbda4bdcc-0a88-4af3-8c17-2e4e860141cf.png</url>
      <title>DEV Community: vikrampawar</title>
      <link>https://dev.to/vikrampawar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vikrampawar"/>
    <language>en</language>
    <item>
      <title>Feature toggle/flag</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Wed, 17 Jun 2020 20:35:01 +0000</pubDate>
      <link>https://dev.to/vikrampawar/feature-toggle-flag-5db1</link>
      <guid>https://dev.to/vikrampawar/feature-toggle-flag-5db1</guid>
      <description>&lt;p&gt;It's the idea of having a bunch of &lt;code&gt;if&lt;/code&gt;statements in your code to turn a new feature 'on' or 'off'. It sounds a bit crazy when we put it that way, but it has a useful function. &lt;/p&gt;

&lt;p&gt;This technique is used to push a new feature to production and test it by turning the feature 'on' for a small subset of your users. This is used in continuous delivery environments to deliver code to production as soon as it's ready, but at the same time reduce the impact if it doesn't work as expected, or, has a bug that can manifest only in production environment. &lt;/p&gt;

&lt;p&gt;Once you gain confidence that the feature is working for the small subset of users, you gradually expose other users to the feature.  &lt;/p&gt;

&lt;p&gt;A slightly more advanced version of this was done by GitHub. They built a tool called Scientist which allowed them to compare the output of the new feature against the output of the existing feature and log the difference, but use the old feature to serve the user for now. Later, they went through the log to understand if the differences seen were expected ones or not. After seeing a sufficient number of these logs, and when their confidence in the new feature was established, they turned this feature 'on' for everybody. &lt;/p&gt;

</description>
      <category>release</category>
    </item>
    <item>
      <title>Efficiency and Abundance</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Tue, 16 Jun 2020 21:44:47 +0000</pubDate>
      <link>https://dev.to/vikrampawar/efficiency-and-abundance-16fg</link>
      <guid>https://dev.to/vikrampawar/efficiency-and-abundance-16fg</guid>
      <description>&lt;p&gt;When you have scarcity, efficiency is a virtue. It allows you to make the most of your resources. However, if you have abundance, efficiency is no longer a virtue in the same respect.&lt;/p&gt;

&lt;p&gt;Efficiency is hard. It is unpleasant to be efficient. It requires a lot more discipline. So, efficiency is rare. We are not efficient if there is no compelling need. That is, we abandon efficiency, as soon as we understand that efficiency is no longer making the difference.&lt;/p&gt;

&lt;p&gt;Now, let us see where these ideas make sense. In the early days of computing, resources were limited. So, efficiency was important. People tried to save resources every way they could. So, a lot of applications that were developed were developed with razor sharp focus on not wasting any resource, i.e, everything was made as efficient as was possible. So computing or developing software was not pleasant, not many people could do it, or wanted to do it. &lt;/p&gt;

&lt;p&gt;But as computing resources became cheaper, and abundant, there was no longer the need to be very efficient in many types of development. It was okay if your program consumes 10 times, 100 times more memory, or disk space, or it does totally unnecessary work, many times over. It became possible, easy, and pleasant to write software this way that met the real needs of business. &lt;/p&gt;

</description>
      <category>tangent</category>
    </item>
    <item>
      <title> What is a Message?</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Tue, 16 Jun 2020 20:11:08 +0000</pubDate>
      <link>https://dev.to/vikrampawar/what-is-a-message-37o2</link>
      <guid>https://dev.to/vikrampawar/what-is-a-message-37o2</guid>
      <description>&lt;p&gt;What is a &lt;code&gt;Message&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Here is a good definition of a &lt;a href="https://www.enterpriseintegrationpatterns.com/patterns/messaging/Message.html"&gt;Message&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I want to develop your intuition about a &lt;code&gt;Message&lt;/code&gt;, so I'll elaborate this concept.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Message&lt;/code&gt; is an overused word. I want to develop intuition about a &lt;code&gt;Message&lt;/code&gt; as used in Software Development.&lt;/p&gt;

&lt;p&gt;Now let us suppose two people Alice and Bob want to communicate. If Alice shouts at Bob, we can't say Alice has given a &lt;code&gt;Message&lt;/code&gt; to Bob. If instead, Alice tells Charlie something about Bob, and Charlie goes and tells it to Bob, we can say Charlie has passed on a &lt;code&gt;Message&lt;/code&gt; to Bob. &lt;/p&gt;

&lt;p&gt;What is the difference between the two situations? Of course, I introduced Charlie. But, Alice could have written the same thing in a piece of paper and sent that to Bob, or Alice could have sent an email or a text that has the same content, and in all these cases, we would say that Alice has sent Bob, a &lt;code&gt;Message&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, the fundamental thing that makes a &lt;code&gt;Message&lt;/code&gt; a &lt;code&gt;Message&lt;/code&gt; is that it leaves one person and then goes to another person. It has an independent existence outside of both people. And, because it leaves one person and then goes to another person, a &lt;code&gt;Message&lt;/code&gt; by necessity needs to have the following information for it to be considered a &lt;code&gt;Message&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It needs to have the information about where is it coming from, where is it going to, what is it about, and finally the actual content. These are called &lt;code&gt;Sender&lt;/code&gt;, &lt;code&gt;Recipient&lt;/code&gt;, &lt;code&gt;Type&lt;/code&gt; (Subject) and &lt;code&gt;Payload&lt;/code&gt;, respectively. The &lt;code&gt;Sender&lt;/code&gt;, &lt;code&gt;Recipient&lt;/code&gt; and &lt;code&gt;Type&lt;/code&gt; are grouped together as a &lt;code&gt;Header&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The same concept is used when information leaves one Application and goes to another Application. &lt;/p&gt;

&lt;p&gt;An email, or a text, that we send is a &lt;code&gt;Message&lt;/code&gt;. It has a &lt;code&gt;Header&lt;/code&gt;, i.e, &lt;code&gt;Sender&lt;/code&gt;, &lt;code&gt;Recipient&lt;/code&gt; and &lt;code&gt;Type&lt;/code&gt; along with the &lt;code&gt;Payload&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;Message&lt;/code&gt; can be a lot more things, it can have a lot more information, but the &lt;code&gt;Header&lt;/code&gt; and the &lt;code&gt;Payload&lt;/code&gt; are the absolute minimum information that it needs to have for it to be able to leave one person or an Application, be independent, and reach the right &lt;code&gt;Recipient&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>message</category>
    </item>
    <item>
      <title> What is a CIDR</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Mon, 15 Jun 2020 11:37:17 +0000</pubDate>
      <link>https://dev.to/vikrampawar/what-is-a-cidr-2159</link>
      <guid>https://dev.to/vikrampawar/what-is-a-cidr-2159</guid>
      <description>&lt;p&gt;The Wikipedia link is here &lt;a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing"&gt;Classless Inter-domain Routing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is the basic information you need to know.&lt;/p&gt;

&lt;p&gt;A CIDR identifies a machine connected to a network.&lt;/p&gt;

&lt;p&gt;An example CIDR for IPV4 address looks like this &lt;code&gt;192.168.100.14/24&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The numbers &lt;code&gt;192&lt;/code&gt;, &lt;code&gt;168&lt;/code&gt;, &lt;code&gt;100&lt;/code&gt;, &lt;code&gt;14&lt;/code&gt; are four octets. An octet represents &lt;code&gt;8&lt;/code&gt; bits. We use four octets, so we are using &lt;code&gt;32&lt;/code&gt; bits to represent the machine. &lt;/p&gt;

&lt;p&gt;A bit can have two possibilities either &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;. So, an octet can have 256 (2 ** 8) values, starting from 0 and ending with 255, which means 4 octets can represent 4,294,967,296 possibilities (2 ** 32).&lt;/p&gt;

&lt;p&gt;But, the number after the &lt;code&gt;/&lt;/code&gt; puts a limit on this.&lt;/p&gt;

&lt;p&gt;Before, I explain how the limit is applied, I'll have to explain what number &lt;code&gt;24&lt;/code&gt; means. The number &lt;code&gt;24&lt;/code&gt; could also have been represented as 4 octets. If we did, it would look like &lt;code&gt;255.255.255.0&lt;/code&gt;. The number &lt;code&gt;24&lt;/code&gt; is a compact way of representing these 4 octets. Are you wondering how these are equivalent? The value &lt;code&gt;255&lt;/code&gt; when represented by a an octet (8 bits) looks like this &lt;code&gt;11111111&lt;/code&gt;. So &lt;code&gt;255.255.255.0&lt;/code&gt; would be &lt;code&gt;11111111.11111111.11111111.00000000&lt;/code&gt;. I put &lt;code&gt;.&lt;/code&gt; in between for readability. As you can see, this big number has &lt;code&gt;24&lt;/code&gt; leading bits set to &lt;code&gt;1&lt;/code&gt;. That's the link between the two representations.&lt;/p&gt;

&lt;p&gt;This number is telling us that while using the address &lt;code&gt;192.168.100.14&lt;/code&gt;, don't use the first 24 bits or the first 3 octets. That is, &lt;code&gt;192.168.100&lt;/code&gt; are off limits. That leaves us with only the last octet, so only 256 possible values :( ! Imagine if this number was &lt;code&gt;31&lt;/code&gt;, that leaves only &lt;code&gt;1&lt;/code&gt; bit or two possibilities. &lt;/p&gt;

&lt;p&gt;The 3 octets that we do not use, along with a a &lt;code&gt;0&lt;/code&gt; for the fourth octet &lt;code&gt;192.168.100.0&lt;/code&gt; represents something called a &lt;code&gt;routing prefix&lt;/code&gt;. If you represent this routing prefix in the form &lt;code&gt;255.255.255.0&lt;/code&gt;, it's called the &lt;code&gt;subnet mask&lt;/code&gt; and logically represents the same thing.&lt;/p&gt;

</description>
      <category>cidr</category>
      <category>networking</category>
    </item>
    <item>
      <title>Monolith/Microservices to Family/Company analogy</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Sun, 14 Jun 2020 23:21:38 +0000</pubDate>
      <link>https://dev.to/vikrampawar/monolith-microservices-to-family-company-analogy-2029</link>
      <guid>https://dev.to/vikrampawar/monolith-microservices-to-family-company-analogy-2029</guid>
      <description>&lt;p&gt;Today I was reading Chris Richardson's book Microservices Architecture and it struck me that the Monolith to Microservices relation is analogous to that of a Family and Company.&lt;/p&gt;

&lt;p&gt;Firstly, from a very high level view, both Monolith diagrams and Microservices diagrams have a bunch of boxes with various connections between them. What is the fundamental difference between them? The main difference is how the boxes are related. The boxes in the Microservices talk to each other only via Interprocess connection. Every other difference between the two architectures stems from this basic difference. There is no such restriction in the Monolith. &lt;/p&gt;

&lt;p&gt;If you consider a family business run by a close-knit family. They generally tend work very efficiently as a group and accomplish a lot more than a group of strangers. There are many reasons for this, but the primary reason is that they have a very strong informal communication amongst themselves. &lt;/p&gt;

&lt;p&gt;This works really well up to a point. If the business grows beyond the capacity of the family,  they need to get outsiders to help them, Then things change. Their existing communication patterns won't work. They'll have to develop some formal ways of interacting with the outsiders. Once these formal ways are developed, then they can bring in a lot many outsiders and accomplish a lot more. People can be easily replaced as well.  They can become a much bigger company. &lt;/p&gt;

&lt;p&gt;Similarly, the communication between the boxes in a monolith are easy and don't require too much formality. However when the communication is constrained between boxes as in Microservices where it is forced to happen via Interprocess communication, it needs to become a lot more formal. The communication has to be via formal contracts. So the boxes become independent. They can be replaced with other boxes. More boxes can be brought in. &lt;/p&gt;

&lt;p&gt;So, although communication between any two entities is constrained and formal and therefore poorer, it paves the way for the system to grow larger. &lt;/p&gt;

</description>
      <category>microservices</category>
    </item>
    <item>
      <title>DEV posts on Stackbit</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Sun, 14 Jun 2020 15:09:04 +0000</pubDate>
      <link>https://dev.to/vikrampawar/dev-posts-on-stackbit-3ppm</link>
      <guid>https://dev.to/vikrampawar/dev-posts-on-stackbit-3ppm</guid>
      <description>&lt;p&gt;I followed the &lt;a href="https://dev.to/connecting-with-stackbit"&gt;DEV post&lt;/a&gt; to build &lt;a href="https://vikrampawar-sb-636a9.netlify.app/?stackbit=3330780793b816842607efd04521fdba7312c396beafd50a06cc3a9ebd79a02b"&gt;this site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, any posts I write on DEV will be automatically published to that site. &lt;/p&gt;

&lt;p&gt;I did all this on an iPad.&lt;/p&gt;

&lt;p&gt;I was hoping that I’d find a Markdown file for each of my posts. But, the generated repo on GitHub only has Javascript files.  &lt;/p&gt;

&lt;p&gt;The next step would be to publish to DEV from a GitHub repo. When I’m on a PC, I prefer to use a text editor to write the posts. I currently have a GitHub pages blog that is automatically generated from a GitHub repo. It would be nice to setup a workflow such that when I post to that repo it is published on DEV as well. &lt;/p&gt;

</description>
      <category>blogging</category>
    </item>
    <item>
      <title>The Scale Cube</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Sun, 14 Jun 2020 12:21:02 +0000</pubDate>
      <link>https://dev.to/vikrampawar/the-scale-cube-5a2c</link>
      <guid>https://dev.to/vikrampawar/the-scale-cube-5a2c</guid>
      <description>&lt;p&gt;The Art of Scalability (Addison-Wesley, 2015) talks about  Scale Cube. Here is an adaptation of the concept in the context of messaging. &lt;/p&gt;

&lt;p&gt;X axis scaling is having more than one message flow to process messages. That is, having more instances of the flow running. &lt;/p&gt;

&lt;p&gt;Y axis scaling is having one message flow for each kind of message. Say one flow for one country. &lt;/p&gt;

&lt;p&gt;Z axis scaling is splitting the message into smaller parts say instead of having both order and customer in the same message, have a separate order message, and a customer message.&lt;/p&gt;

</description>
      <category>scalability</category>
      <category>microservices</category>
    </item>
    <item>
      <title> Select any open tab in Sublime, VS Code, and Eclipse with ease</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Fri, 12 Jun 2020 17:43:44 +0000</pubDate>
      <link>https://dev.to/vikrampawar/select-any-open-tab-in-sublime-vs-code-and-eclipse-with-ease-2ibk</link>
      <guid>https://dev.to/vikrampawar/select-any-open-tab-in-sublime-vs-code-and-eclipse-with-ease-2ibk</guid>
      <description>&lt;p&gt;When working in text editors and IDEs, it's natural to have several tabs open. To work efficiently with the tabs, it is good to be acquainted with the commands we can use to quickly move between the tabs.&lt;/p&gt;

&lt;p&gt;I use Eclipse extensively as I do development in Java and IBM ESQL. I have been using Sublime for quite some time, and I've recently started using VS Code. The first thing I did was to opt for Sublime key-bindings in VS Code. So the actual key-bindings of the commands I mention below may be different.&lt;/p&gt;

&lt;p&gt;Now coming to the topic of the post, first and basic way to work with tabs is to be able to cycle between the tabs.&lt;/p&gt;

&lt;p&gt;In Eclipse, I can cycle between the open tabs using &lt;code&gt;cntrl-F6&lt;/code&gt;. In Sublime (and VS Code), I can use &lt;code&gt;ctrl-tab&lt;/code&gt; and &lt;code&gt;ctrl-shift-tab&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The next level up would be to get a list of all the open tabs and select the one I want. In Eclipse, I can press &lt;code&gt;ctrl-e&lt;/code&gt; to get a list of open tabs and then I can type a few characters to filter the list, and select the tab I want.&lt;/p&gt;

&lt;p&gt;Today, I discovered that I can use the same key combination &lt;code&gt;ctrl-e&lt;/code&gt; in Sublime and it works exactly as in Eclipse. &lt;/p&gt;

&lt;p&gt;So, I suddenly began missing this in Sublime :). I searched and found this helpful &lt;a href="https://stackoverflow.com/questions/38561302/is-there-a-shortcut-for-sublime-text-to-find-an-open-file-eclipse-ctrl-e"&gt;Stack Overflow link&lt;/a&gt;. I implemented the suggestion and now I can use &lt;code&gt;ctrl-e&lt;/code&gt; in Sublime as well and do the same thing.&lt;/p&gt;

&lt;p&gt;Only thing is that &lt;code&gt;ctrl-e&lt;/code&gt; in Sublime actually does something called &lt;code&gt;slurp_find_string&lt;/code&gt; which basically selects the word under cursor as the string to search for in a find command. I won't be able to use it now unless I map it to a new key. I resist using new key combinations.  I never really use this command in that much in Sublime. So, I'll leave it for now. I remember that I used to like a similar feature in Vim, where I could press '*' and the cursor moves to next occurrence of the word under cursor.&lt;/p&gt;

&lt;p&gt;Sometimes using a new tool teaches us something that makes us look at familiar tools in a new light. So, although I know that all editors more or less do the same thing, I still play around with new ones to learn new things.&lt;/p&gt;

</description>
      <category>sublime</category>
      <category>vscode</category>
      <category>eclipse</category>
      <category>tab</category>
    </item>
    <item>
      <title> Same Repo On Both Bitbucket And Github</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Thu, 11 Jun 2020 18:58:40 +0000</pubDate>
      <link>https://dev.to/vikrampawar/same-repo-on-both-bitbucket-and-github-jpa</link>
      <guid>https://dev.to/vikrampawar/same-repo-on-both-bitbucket-and-github-jpa</guid>
      <description>&lt;p&gt;I used bitbucket as my main remote hub for some years now. The main reason was that we use bitbucket at work, so I was more familiar with it. The other reason of course was that I could host my private repositories there. Now Github also allows hosting of private repositories, so I wanted to add Github as another remote to my existing git repositories. Here is what I did.&lt;/p&gt;

&lt;p&gt;First I checked what is the remote by using the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Shows remote&lt;/span&gt;
git remote &lt;span class="nt"&gt;-v&lt;/span&gt; show

&lt;span class="c"&gt;### output&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then I looked at the git config in a text editor.&lt;/p&gt;

&lt;p&gt;The config is in the file  &lt;code&gt;.git/config&lt;/code&gt;. It has an entry as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;remote &lt;span class="s2"&gt;"origin"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
    url &lt;span class="o"&gt;=&lt;/span&gt; https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git
    fetch &lt;span class="o"&gt;=&lt;/span&gt; +refs/heads/&lt;span class="k"&gt;*&lt;/span&gt;:refs/remotes/origin/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To set Github as another remote, I ran the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote set-url origin &lt;span class="nt"&gt;--add&lt;/span&gt; git@github.com:vikrampawar/javaprojects.git

&lt;span class="c"&gt;### output&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
origin  git@github.com:vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This added the remote to the config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;remote &lt;span class="s2"&gt;"origin"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
    url &lt;span class="o"&gt;=&lt;/span&gt; https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git
    fetch &lt;span class="o"&gt;=&lt;/span&gt; +refs/heads/&lt;span class="k"&gt;*&lt;/span&gt;:refs/remotes/origin/&lt;span class="k"&gt;*&lt;/span&gt;
    url &lt;span class="o"&gt;=&lt;/span&gt; git@github.com:vikrampawar/javaprojects.git   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I had issues. So, I first created an empty project called 'javaprojects' on Github, and then I also changed the protocol to https instead of git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt; show
&lt;span class="c"&gt;### output&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://Vikrampawar@bitbucket.org/Vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://github.com/vikrampawar/javaprojects.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When I did a push, it worked. I have the repo on Github as well now.&lt;/p&gt;

&lt;p&gt;This only works one way now. I can push changes to Github, but I can't pull from it. I'll do that setup later.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>bitbucket</category>
    </item>
    <item>
      <title>Java Streams operate on the whole set</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Sun, 31 May 2020 17:10:14 +0000</pubDate>
      <link>https://dev.to/vikrampawar/java-streams-operate-on-the-whole-set-4fac</link>
      <guid>https://dev.to/vikrampawar/java-streams-operate-on-the-whole-set-4fac</guid>
      <description>&lt;p&gt;Streams can help us do a lot of processing that we would traditionally do using Collections. However, there are some crucial differences between the two.&lt;/p&gt;

&lt;p&gt;Collections operate on memory. By the time we use collections, all the elements of the collection are already in memory and are accessible. Streams operate on a set of elements all of which are not yet in memory. Streams can be infinite as well.&lt;/p&gt;

&lt;p&gt;Collection operations are imperative. They work on one item at a time. Stream operations work on the whole set. It's a bit amusing that, although the whole collection is in memory, collection operations work on one item at a time, whereas, the Stream operations work on the whole set, although not all of the items are in memory. &lt;/p&gt;

&lt;p&gt;Consider the below java code. It produces the Pythogorean triplets in a given range of integers. These are numbers that satisfy the equation &lt;code&gt;a*a + b*b = c*c&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; 
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)}))&lt;/span&gt;  
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First, obtain a stream of the range of integers using &lt;code&gt;IntStream.rangeClosed(1, 10)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;From this, obtain a stream of Integers using &lt;code&gt;boxed()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;From this, obtain all possible triplets using &lt;code&gt;flatMap()&lt;/code&gt;. (See a demo of the &lt;a href="https://vikrampawar.github.io/java/streams/flatmap/2020/05/31/Java-Streams-Flatmap.html"&gt;flatMap&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, filter only those that satisfy the equation.&lt;/p&gt;

&lt;p&gt;Note that after each operation, we end up with a stream. We don't operate on individual elements, but the whole set. The below program shows the output after each step.&lt;/p&gt;

&lt;p&gt;Also, in the complete program below, note the suble difference in the two ways the final filter can be applied. In the first version, the filter is applied after the &lt;code&gt;flatMap&lt;/code&gt; operation and in the second version, the filter is applied within the &lt;code&gt;flatMap&lt;/code&gt; operation. The final result is the same in both cases.&lt;/p&gt;

&lt;p&gt;The complete program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.stream.IntStream&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PythogoreanTriplets&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 1 - Get stream of Integers 1 to 10 \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;     
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 2 - Get possible triplets \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;      
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)}))&lt;/span&gt;                      
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]))&lt;/span&gt;
                &lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 3a - Filter the right ones, one way \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; 
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)}))&lt;/span&gt;  
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]));&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 3b - Filter the right ones, another way \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; 
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)})&lt;/span&gt;  
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]));&lt;/span&gt;

    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The example is based on an example from the book &lt;a href="https://www.amazon.co.uk/Modern-Java-Action-functional-programming/dp/1617293563/ref=sr_1_1?dchild=1&amp;amp;keywords=modern+java+development&amp;amp;qid=1590920080&amp;amp;sr=8-1"&gt;Modern Java Development&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The output will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1 - Get stream of Integers 1 to 10 
------
1 2 3 4 5 6 7 8 9 10 

Step 2 - Get possible triplets 
------
1.0, 1.0, 1.4142135623730951
1.0, 2.0, 2.23606797749979
1.0, 3.0, 3.1622776601683795
1.0, 4.0, 4.123105625617661
1.0, 5.0, 5.0990195135927845
1.0, 6.0, 6.082762530298219
1.0, 7.0, 7.0710678118654755
1.0, 8.0, 8.06225774829855
1.0, 9.0, 9.055385138137417
1.0, 10.0, 10.04987562112089
2.0, 2.0, 2.8284271247461903
2.0, 3.0, 3.605551275463989
2.0, 4.0, 4.47213595499958
2.0, 5.0, 5.385164807134504
2.0, 6.0, 6.324555320336759
2.0, 7.0, 7.280109889280518
2.0, 8.0, 8.246211251235321
2.0, 9.0, 9.219544457292887
2.0, 10.0, 10.198039027185569
3.0, 3.0, 4.242640687119285
3.0, 4.0, 5.0
3.0, 5.0, 5.830951894845301
3.0, 6.0, 6.708203932499369
3.0, 7.0, 7.615773105863909
3.0, 8.0, 8.54400374531753
3.0, 9.0, 9.486832980505138
3.0, 10.0, 10.44030650891055
4.0, 4.0, 5.656854249492381
4.0, 5.0, 6.4031242374328485
4.0, 6.0, 7.211102550927978
4.0, 7.0, 8.06225774829855
4.0, 8.0, 8.94427190999916
4.0, 9.0, 9.848857801796104
4.0, 10.0, 10.770329614269007
5.0, 5.0, 7.0710678118654755
5.0, 6.0, 7.810249675906654
5.0, 7.0, 8.602325267042627
5.0, 8.0, 9.433981132056603
5.0, 9.0, 10.295630140987
5.0, 10.0, 11.180339887498949
6.0, 6.0, 8.48528137423857
6.0, 7.0, 9.219544457292887
6.0, 8.0, 10.0
6.0, 9.0, 10.816653826391969
6.0, 10.0, 11.661903789690601
7.0, 7.0, 9.899494936611665
7.0, 8.0, 10.63014581273465
7.0, 9.0, 11.40175425099138
7.0, 10.0, 12.206555615733702
8.0, 8.0, 11.313708498984761
8.0, 9.0, 12.041594578792296
8.0, 10.0, 12.806248474865697
9.0, 9.0, 12.727922061357855
9.0, 10.0, 13.45362404707371
10.0, 10.0, 14.142135623730951


Step 3a - Filter the right ones, one way 
------
3.0, 4.0, 5.0
5.0, 12.0, 13.0
6.0, 8.0, 10.0
8.0, 15.0, 17.0
9.0, 12.0, 15.0


Step 3b - Filter the right ones, another way 
------
3.0, 4.0, 5.0
5.0, 12.0, 13.0
6.0, 8.0, 10.0
8.0, 15.0, 17.0
9.0, 12.0, 15.0

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://vikrampawar.github.io/java/streams/2020/05/31/Java-Streams-operate-on-the-whole-set.html"&gt;blogpost&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>streams</category>
    </item>
    <item>
      <title>Java Streams flatMap Demo</title>
      <dc:creator>vikrampawar</dc:creator>
      <pubDate>Sun, 31 May 2020 17:06:41 +0000</pubDate>
      <link>https://dev.to/vikrampawar/java-streams-flatmap-demo-k43</link>
      <guid>https://dev.to/vikrampawar/java-streams-flatmap-demo-k43</guid>
      <description>&lt;p&gt;The below example shows how we can use &lt;code&gt;flatMap()&lt;/code&gt; to get the unique combination of two integers for all integers up to n. For n=3, this would be&lt;br&gt;
(1, 1) (1, 2) (1, 3) (2, 2) (2, 3) (3, 3).&lt;/p&gt;

&lt;p&gt;To obtain a stream of 3 integers (1, 2, 3) use &lt;code&gt;IntStream.rangeClosed(1, 3)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Map works with a stream of types, so convert this to a stream of 3 Integers by using &lt;code&gt;.boxed()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now starting from 1, we want to make a combination of that number with each  integer following it. &lt;/p&gt;

&lt;p&gt;So for each &lt;code&gt;i&lt;/code&gt; we can obtain another stream by &lt;code&gt;IntStream.rangeClosed(i, n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we use &lt;code&gt;map()&lt;/code&gt;, as below, we'll end up with a stream of streams.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map(a -&amp;gt; IntStream.rangeClosed(a, 3)
    .mapToObj( b -&amp;gt; new double[]{a, b}))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This would be a stream of 3 streams. The first stream will have [1, 1] [1, 2] [1, 3], the second will have [2, 2] and [2, 3]. The third will have [3, 3].&lt;/p&gt;

&lt;p&gt;If instead, we use &lt;code&gt;flatMap()&lt;/code&gt; as below, we'll end up with one stream.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flatMap(a -&amp;gt; IntStream.rangeClosed(a, 3)
    .mapToObj( b -&amp;gt; new double[]{a, b}))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This would be the stream&lt;br&gt;
[1, 1] [1, 2] [1, 3] [2, 2] [2, 3] [3, 3].&lt;/p&gt;

&lt;p&gt;The complete program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.stream.IntStream&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FlatMapDemo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 1 one primitive integer stream \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;     
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// one stream&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" - primitive "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 2 boxed to Integer stream \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;      
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;// one stream&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" - "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getTypeName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 3 Print stream Regular map \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;     
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;                  &lt;span class="c1"&gt;// regular map, stream of streams&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;}))&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;  &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="s"&gt;" - contains "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n\nStep 4 Print stream Flat map \n------"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;        
        &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;boxed&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flatMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;IntStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rangeClosed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;               &lt;span class="c1"&gt;// flat map, one stream&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mapToObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]{&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;}))&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" - "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getTypeName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" Contents: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The output will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1 one primitive integer stream 
------
1 - primitive , 2 - primitive , 3 - primitive , 

Step 2 boxed to Integer stream 
------
1 - java.lang.Integer, 2 - java.lang.Integer, 3 - java.lang.Integer, 

Step 3 Print stream Regular map 
------
java.util.stream.IntPipeline$1@6aceb1a5 - contains 3
java.util.stream.IntPipeline$1@4c75cab9 - contains 2
java.util.stream.IntPipeline$1@1ef7fe8e - contains 1

Step 4 Print stream Flat map 
------
[I@6979e8cb - int[] Contents: 1, 1
[I@763d9750 - int[] Contents: 1, 2
[I@5c0369c4 - int[] Contents: 1, 3
[I@2be94b0f - int[] Contents: 2, 2
[I@d70c109 - int[] Contents: 2, 3
[I@17ed40e0 - int[] Contents: 3, 3


&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Link to &lt;a href="https://vikrampawar.github.io/java/streams/flatmap/2020/05/31/Java-Streams-Flatmap.html"&gt;blogpost&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>streams</category>
      <category>flatmap</category>
    </item>
  </channel>
</rss>
