<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jai Ludhani on Medium]]></title>
        <description><![CDATA[Stories by Jai Ludhani on Medium]]></description>
        <link>https://medium.com/@jailudhani?source=rss-ce32790dfad3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*js4FIq_9KRWkO2EA.</url>
            <title>Stories by Jai Ludhani on Medium</title>
            <link>https://medium.com/@jailudhani?source=rss-ce32790dfad3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:07:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jailudhani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java 8 Stream Programming Questions]]></title>
            <link>https://medium.com/@jailudhani/java-8-stream-programming-questions-29f3b8faa5e5?source=rss-ce32790dfad3------2</link>
            <guid isPermaLink="false">https://medium.com/p/29f3b8faa5e5</guid>
            <category><![CDATA[java-8-feature]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[java8-stream-api]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Jai Ludhani]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 06:28:07 GMT</pubDate>
            <atom:updated>2024-01-04T06:28:07.093Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java 8 Stream Programming Question</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lEzNCm72wKHyfpmkxAw4hw.png" /></figure><p>I had recently gone through interview process of some of the well known companies who were hiring for <strong>Lead Java Developer</strong> position.</p><p>Companies wanted to check knowledge around Java 8 features particularly how much level, developer is familier with application of lambda function.</p><p>Please note that Java 8 LTS date is extended till 2030.</p><p>Below are the questions, that I faced during interview.</p><ol><li><strong><em>Flatten the given array of Object</em></strong></li></ol><pre> Object[] inputArray = { 1, 2, new Object[]{ 3, 4, new Object[]{ 5 }, 6, 7 }, 8, 9, 10 };<br>  <br> List&lt;Object&gt; ansList = flatten(inputArray); // need to implement flatten method</pre><p>Lets try it first without stream API.</p><p>We will check that if presentElement is <strong><em>instanceOf</em></strong><em> </em>Object[], then we recursively call <strong><em>flatten</em></strong> method, otherwise we will add the presentElement into our <strong><em>answerList</em></strong>.</p><pre>public List&lt;Object&gt; flatten(Object[] inputArray) throws Exception {<br>   List&lt;Object&gt; answerList = new ArrayList&lt;&gt;();<br><br>   for (Object presentElement : inputArray) {<br>      if (presentElement instanceof Object[]) {<br>          answerList.addAll(flatten((Object[]) presentElement));<br>      } else {<br>         answerList.add(presentElement);<br>      }<br>   }<br>   return answerList;<br>}</pre><p>How we will do using lambda ?</p><p>Definitely we need to iterate, so stream() is required and we need to flatten the array into a integer element, so we can use <strong><em>flatMap</em></strong> with condition that described while writing above code which is without stream, we have implemented.</p><pre>public List&lt;Object&gt; flatten(Object[] array) {<br>        return Arrays.stream(array)<br>                .flatMap(o -&gt; o instanceof Object[] ? flatten((Object[]) o).stream() : Stream.of(o))<br>                .collect(Collectors.toList());<br>    }</pre><p>That’s it for time being, Will continue this series with further questions that I had faced in recent interviews.</p><p>Please clap, If this narrative contributed any new knowledge to your expertise.</p><p><strong>Thanks</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29f3b8faa5e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>