<?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 Mete Ergin on Medium]]></title>
        <description><![CDATA[Stories by Mete Ergin on Medium]]></description>
        <link>https://medium.com/@meteergin?source=rss-a64f30cec4b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PpgFqfDH2ovZG4VyTg5H0w.jpeg</url>
            <title>Stories by Mete Ergin on Medium</title>
            <link>https://medium.com/@meteergin?source=rss-a64f30cec4b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:37:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meteergin/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[Spring Boot implementation of JPAstreamer]]></title>
            <link>https://meteergin.medium.com/spring-boot-implementation-of-jpastreamer-bf7d66b17000?source=rss-a64f30cec4b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf7d66b17000</guid>
            <category><![CDATA[jpa]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-framework]]></category>
            <dc:creator><![CDATA[Mete Ergin]]></dc:creator>
            <pubDate>Wed, 25 Aug 2021 18:58:05 GMT</pubDate>
            <atom:updated>2021-08-25T18:58:05.421Z</atom:updated>
            <content:encoded><![CDATA[<p>JPAstreamer is a library for expressing JPA queries by the usage of Java Streams. Your application may immediately act on database components using known Stream operators such as filter(), sort(), and map() with just one dependency. As a result, your queries will be more expressive, intuitive, and less likely to contain errors. You can check for best practices of Java Streams from my previous <a href="https://medium.com/@meteergin/java-streams-best-practices-1f4444fde921">post</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I7myMP1ofewOUpup" /><figcaption>Photo by <a href="https://unsplash.com/@nousnou?utm_source=medium&amp;utm_medium=referral">nousnou iwasaki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For demonstration purposes, I wrote a simple Spring Boot rest project. Also, I added the <a href="https://speedment.github.io/jpa-streamer/jpa-streamer/1.0.1/get-jpa-streamer/spring_integration.html">JPAStreamer library</a> and the Fake Name Generator library which is called <a href="https://github.com/DiUS/java-faker">Java Faker</a>. On the service layer, I both implemented JPA and JPAStreamer for the same queries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c2924ba996016fb3924b6f7cf48dd77/href">https://medium.com/media/0c2924ba996016fb3924b6f7cf48dd77/href</a></iframe><p>In order not to get lost in the details I chose the H2 database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d44a1b6093a5d3ee82b52b98047f24/href">https://medium.com/media/93d44a1b6093a5d3ee82b52b98047f24/href</a></iframe><p>The User entity is used for the base sample data type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72c9a0e9899f1e6ab6d939d4f95142dc/href">https://medium.com/media/72c9a0e9899f1e6ab6d939d4f95142dc/href</a></iframe><p>I ran the following code at the bootstrap to get test data which contains 100 random User and saved them to the database. All data can be observed over the <a href="http://localhost:8080/h2-console">H2 console</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd40835a15171b800377bd8acdeb9a39/href">https://medium.com/media/fd40835a15171b800377bd8acdeb9a39/href</a></iframe><p>For expanding UserRepository I added 7 methods with the usage of <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation">Spring Boot JPA implementation syntax</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66fe4bb6bc39167e1ed4a1f2480b464a/href">https://medium.com/media/66fe4bb6bc39167e1ed4a1f2480b464a/href</a></iframe><p>On service layer, I implemented both JPA Repository and JPA Streamer versions of findAll, findById, findByAge, findByFirstCharacterOfFirstName, findByLessThanAge, findByFirstCharacterOfFirstNameAndAge, findByAgeRange and findMaximumAge methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ef01eb4dc0f760938e1703a7d0e0ee3/href">https://medium.com/media/3ef01eb4dc0f760938e1703a7d0e0ee3/href</a></iframe><p>For the controller layer, I wrote a simple IUserController interface that is implemented in both JpaRepositoryUserController and JpaStreamerUserController. Due to I wanted to demonstrate how to get the same results from different rest requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a14f53d3736aba0eec6efb4d93c729a/href">https://medium.com/media/3a14f53d3736aba0eec6efb4d93c729a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e6ce4423a6b83a341df6a4b31b350fd/href">https://medium.com/media/2e6ce4423a6b83a341df6a4b31b350fd/href</a></iframe><p>When I started the application, 100 <strong>random</strong> User is saved to the database. So, the demonstration that I will show you would differ from your own results. Let’s try it out;</p><ol><li>findAll</li></ol><pre>curl <a href="http://localhost:8080/user/jpa-repository/all">http://localhost:8080/user/jpa-repository/all</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/all">http://localhost:8080/user/jpa-streamer/all</a></pre><p>On the console, I got the same SQL queries for both requests.</p><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ order by user0_.id asc</pre><p>And the responses are the same;</p><pre>[{&quot;id&quot;:1,&quot;firstName&quot;:&quot;Meri&quot;,&quot;lastName&quot;:&quot;Langworth&quot;,&quot;age&quot;:21},{&quot;id&quot;:2,&quot;firstName&quot;:&quot;Towanda&quot;,&quot;lastName&quot;:&quot;Runolfsdottir&quot;,&quot;age&quot;:58},{&quot;id&quot;:3,&quot;firstName&quot;:&quot;Rubin&quot;,&quot;lastName&quot;:&quot;Sauer&quot;,&quot;age&quot;:94},{&quot;id&quot;:4,&quot;firstName&quot;:&quot;Tia&quot;,&quot;lastName&quot;:&quot;Mante&quot;,&quot;age&quot;:71},....</pre><p>I will not write long details for the next demonstrations. The process will be the same.</p><p>2. findById</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/17">http://localhost:8080/user/jpa-repository/17</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/17">http://localhost:8080/user/jpa-streamer/17</a></pre><pre>Hibernate: select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where user0_.id=?</pre><pre>{&quot;id&quot;:17,&quot;firstName&quot;:&quot;Sang&quot;,&quot;lastName&quot;:&quot;Windler&quot;,&quot;age&quot;:92}</pre><p>3. findByFirstCharacterOfFirstName</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findByFirstCharacterOfFirstName/E">http://localhost:8080/user/jpa-repository/findByFirstCharacterOfFirstName/E</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findByFirstCharacterOfFirstName/E">http://localhost:8080/user/jpa-streamer/findByFirstCharacterOfFirstName/E</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where user0_.first_name like ?</pre><pre>[{&quot;id&quot;:13,&quot;firstName&quot;:&quot;Earleen&quot;,&quot;lastName&quot;:&quot;Cartwright&quot;,&quot;age&quot;:25},{&quot;id&quot;:39,&quot;firstName&quot;:&quot;Erick&quot;,&quot;lastName&quot;:&quot;Douglas&quot;,&quot;age&quot;:66},{&quot;id&quot;:40,&quot;firstName&quot;:&quot;Esmeralda&quot;,&quot;lastName&quot;:&quot;Casper&quot;,&quot;age&quot;:41},{&quot;id&quot;:71,&quot;firstName&quot;:&quot;Elisabeth&quot;,&quot;lastName&quot;:&quot;Emard&quot;,&quot;age&quot;:70}]</pre><p>4. findByAge</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findByAge/7">http://localhost:8080/user/jpa-repository/findByAge/7</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findByAge/7">http://localhost:8080/user/jpa-streamer/findByAge/7</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where user0_.age=?</pre><pre>[{&quot;id&quot;:6,&quot;firstName&quot;:&quot;Otis&quot;,&quot;lastName&quot;:&quot;Murphy&quot;,&quot;age&quot;:7},{&quot;id&quot;:18,&quot;firstName&quot;:&quot;Glen&quot;,&quot;lastName&quot;:&quot;Keebler&quot;,&quot;age&quot;:7},{&quot;id&quot;:21,&quot;firstName&quot;:&quot;Rex&quot;,&quot;lastName&quot;:&quot;Kovacek&quot;,&quot;age&quot;:7}]</pre><p>5. findByLessThanAge</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findByLessThanAge/5">http://localhost:8080/user/jpa-repository/findByLessThanAge/5</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findByLessThanAge/5">http://localhost:8080/user/jpa-streamer/findByLessThanAge/5</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where user0_.age&lt;?</pre><pre>[{&quot;id&quot;:10,&quot;firstName&quot;:&quot;Adolfo&quot;,&quot;lastName&quot;:&quot;Roob&quot;,&quot;age&quot;:0},{&quot;id&quot;:32,&quot;firstName&quot;:&quot;Joeann&quot;,&quot;lastName&quot;:&quot;Stamm&quot;,&quot;age&quot;:0},{&quot;id&quot;:50,&quot;firstName&quot;:&quot;Hunter&quot;,&quot;lastName&quot;:&quot;Kemmer&quot;,&quot;age&quot;:3},{&quot;id&quot;:60,&quot;firstName&quot;:&quot;Margy&quot;,&quot;lastName&quot;:&quot;Robel&quot;,&quot;age&quot;:4},{&quot;id&quot;:64,&quot;firstName&quot;:&quot;Dulcie&quot;,&quot;lastName&quot;:&quot;King&quot;,&quot;age&quot;:0},{&quot;id&quot;:98,&quot;firstName&quot;:&quot;Belle&quot;,&quot;lastName&quot;:&quot;Moen&quot;,&quot;age&quot;:4}]</pre><p>6. findByFirstCharacterOfFirstNameAndAge</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findByFirstCharacterOfFirstNameAndAge/M/4">http://localhost:8080/user/jpa-repository/findByFirstCharacterOfFirstNameAndAge/M/4</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findByFirstCharacterOfFirstNameAndAge/M/4">http://localhost:8080/user/jpa-streamer/findByFirstCharacterOfFirstNameAndAge/M/4</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where (user0_.first_name like ?) and user0_.age=?</pre><pre>[{&quot;id&quot;:60,&quot;firstName&quot;:&quot;Margy&quot;,&quot;lastName&quot;:&quot;Robel&quot;,&quot;age&quot;:4}]</pre><p>7. findByAgeRange</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findByAgeRange/3/7">http://localhost:8080/user/jpa-repository/findByAgeRange/3/7</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findByAgeRange/3/7">http://localhost:8080/user/jpa-streamer/findByAgeRange/3/7</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ where user0_.age between ? and ?</pre><pre>[{&quot;id&quot;:22,&quot;firstName&quot;:&quot;Wilbert&quot;,&quot;lastName&quot;:&quot;Orn&quot;,&quot;age&quot;:5},{&quot;id&quot;:51,&quot;firstName&quot;:&quot;Chun&quot;,&quot;lastName&quot;:&quot;Bartell&quot;,&quot;age&quot;:5},{&quot;id&quot;:60,&quot;firstName&quot;:&quot;Margy&quot;,&quot;lastName&quot;:&quot;Robel&quot;,&quot;age&quot;:4},{&quot;id&quot;:89,&quot;firstName&quot;:&quot;Les&quot;,&quot;lastName&quot;:&quot;Ortiz&quot;,&quot;age&quot;:5},{&quot;id&quot;:98,&quot;firstName&quot;:&quot;Belle&quot;,&quot;lastName&quot;:&quot;Moen&quot;,&quot;age&quot;:4}]</pre><p>8. findMaximumAge</p><pre>curl <a href="http://localhost:8080/user/jpa-repository/findMaximumAge">http://localhost:8080/user/jpa-repository/findMaximumAge</a><br>curl <a href="http://localhost:8080/user/jpa-streamer/findMaximumAge">http://localhost:8080/user/jpa-streamer/findMaximumAge</a></pre><pre>select user0_.id as id1_0_, user0_.age as age2_0_, user0_.first_name as first_na3_0_, user0_.last_name as last_nam4_0_ from user user0_ order by user0_.age desc limit ?</pre><pre>{&quot;id&quot;:52,&quot;firstName&quot;:&quot;Tobias&quot;,&quot;lastName&quot;:&quot;Senger&quot;,&quot;age&quot;:99}</pre><p>In a nutshell, JPAstreamer allows JPA queries to be written as normal Java Streams utilizing short and simple declarative techniques that are type-safe. Our code will be shorter, less complex, and easier to read and maintain as a result.</p><p>All the source codes can be found in my <a href="https://github.com/meteergin/medium-springboot-jpastreamer">Github</a> repository. Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf7d66b17000" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Streams with Simple Examples]]></title>
            <link>https://meteergin.medium.com/java-streams-best-practices-1f4444fde921?source=rss-a64f30cec4b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f4444fde921</guid>
            <category><![CDATA[javastreams]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[collections-in-java]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Mete Ergin]]></dc:creator>
            <pubDate>Sat, 07 Aug 2021 17:57:34 GMT</pubDate>
            <atom:updated>2022-03-27T18:00:40.577Z</atom:updated>
            <content:encoded><![CDATA[<p>Streams and collections resemble each other, but they are designed for distinct goals. Collections provide access management of each object effectively. On the contrary, streams do not directly interest in accessing and manipulating each element it has. Streams are designed to handle parallel and sequential aggregation operations by the usage of method chaining methodology.</p><p>Let’s dig into sample usages;</p><p>At first, create User class. This will represent our base object for samples.</p><pre>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.ToString;</pre><pre><a href="http://twitter.com/Data">@Data</a><br><a href="http://twitter.com/AllArgsConstructor">@AllArgsConstructor</a><br><a href="http://twitter.com/ToString">@ToString</a><br>public class User {<br>    private long id;<br>    private String firstName;<br>    private String lastName;<br>    private int age;<br>    private String nationality;<br>}</pre><p>Let’s write Sampleclass in which all samples run.</p><pre>import java.util.Arrays;<br>import java.util.List;</pre><pre>public class Sample {</pre><pre>    private final List&lt;User&gt; userList = Arrays.asList(<br>            new User(1, &quot;Michael&quot;, &quot;Robert&quot;, 37, &quot;TR&quot;),<br>            new User(2, &quot;Mary&quot;, &quot;Patricia&quot;, 11, &quot;EN&quot;),<br>            new User(3, &quot;John&quot;, &quot;Michael&quot;, 7, &quot;FR&quot;),<br>            new User(4, &quot;Jennifer&quot;, &quot;Linda&quot;, 77, &quot;TR&quot;),<br>            new User(5, &quot;William&quot;, &quot;Elizabeth&quot;, 23, &quot;US&quot;),<br>            new User(6, &quot;Sue&quot;, &quot;Jackson&quot;, 11, &quot;IT&quot;),<br>            new User(7, &quot;Michael&quot;, &quot;Tommy&quot;, 37, &quot;EN&quot;)<br>);<br>    <br>    public static void main(String... args) {<br>        Sample sample = new Sample();<br>    }<br>}</pre><ol><li>Loop over each element of userList by using the <em>forEach()</em> operator and then write to console.</li></ol><pre>public static void main(String... args) {<br>    Sample sample = new Sample();<br>    sample.test1();<br>}</pre><pre>private void test1() {<br>    System.out.println(&quot;Test 1&quot;);</pre><pre>   userList.stream()<br>           .forEach(System.out::println);<br>}</pre><p>Output is;</p><pre>Test 1<br>User(id=1, firstName=Michael, lastName=Robert, age=37, nationality=TR)<br>User(id=2, firstName=Mary, lastName=Patricia, age=11, nationality=EN)<br>User(id=3, firstName=John, lastName=Michael, age=7, nationality=FR)<br>User(id=4, firstName=Jennifer, lastName=Linda, age=77, nationality=TR)<br>User(id=5, firstName=William, lastName=Elizabeth, age=23, nationality=US)<br>User(id=6, firstName=Sue, lastName=Jackson, age=11, nationality=IT)<br>User(id=7, firstName=Michael, lastName=Tommy, age=37, nationality=EN)</pre><p>Due to userList is ArrayList, items are written console with the creation order of the List.</p><p>2. Loop over each element afterward manipulate the object and write to console.</p><pre>private void test2() {<br>     System.out.println(&quot;Test 2&quot;);</pre><pre>     userList.stream()<br>           .map(u -&gt; {<br>              return new User(<br>                      u.getId(),<br>                      &quot;X &quot; + u.getFirstName(),<br>                      &quot;Y &quot; + u.getLastName(),<br>                      u.getAge() + 10),<br>                      u.getNationality());<br>            })<br>           .collect(Collectors.toList())<br>           .forEach(System.out::println);<br>}</pre><p>Output is;</p><pre>Test 2<br>User(id=1, firstName=X Michael, lastName=Y Robert, age=47, nationality=TR)<br>User(id=2, firstName=X Mary, lastName=Y Patricia, age=21, nationality=EN)<br>User(id=3, firstName=X John, lastName=Y Michael, age=17, nationality=FR)<br>User(id=4, firstName=X Jennifer, lastName=Y Linda, age=87, nationality=TR)<br>User(id=5, firstName=X William, lastName=Y Elizabeth, age=33, nationality=US)<br>User(id=6, firstName=X Sue, lastName=Y Jackson, age=21, nationality=IT)<br>User(id=7, firstName=X Michael, lastName=Y Tommy, age=47, nationality=EN)</pre><p>3. Sort the list according to age property.</p><pre>private void test3() {<br>    System.out.println(&quot;Test 3&quot;);</pre><pre>    userList.stream()<br>            .sorted(Comparator.comparing(User::getAge))<br>            .collect(Collectors.toList())<br>            .forEach(System.out::println);<br>}</pre><p>Output is;</p><pre>Test 3<br>User(id=3, firstName=John, lastName=Michael, age=7, nationality=FR)<br>User(id=2, firstName=Mary, lastName=Patricia, age=11, nationality=EN)<br>User(id=6, firstName=Sue, lastName=Jackson, age=11, nationality=IT)<br>User(id=5, firstName=William, lastName=Elizabeth, age=23, nationality=US)<br>User(id=1, firstName=Michael, lastName=Robert, age=37, nationality=TR)<br>User(id=7, firstName=Michael, lastName=Tommy, age=37, nationality=EN)<br>User(id=4, firstName=Jennifer, lastName=Linda, age=77, nationality=TR)</pre><p>4. Sort the list according to age, firstName and lastName property.</p><pre>private void test4() {<br>    System.out.println(&quot;Test 4&quot;);</pre><pre>    userList.stream()<br>            .sorted(Comparator.comparing(User::getAge)<br>                .thenComparing(User::getFirstName)<br>                .thenComparing(User::getLastName))<br>            .collect(Collectors.toList())<br>            .forEach(System.out::println);<br>}</pre><p>Output is;</p><pre>Test 4<br>User(id=3, firstName=John, lastName=Michael, age=7, nationality=FR)<br>User(id=2, firstName=Mary, lastName=Patricia, age=11, nationality=EN)<br>User(id=6, firstName=Sue, lastName=Jackson, age=11, nationality=IT)<br>User(id=5, firstName=William, lastName=Elizabeth, age=23, nationality=US)<br>User(id=1, firstName=Michael, lastName=Robert, age=37, nationality=TR)<br>User(id=7, firstName=Michael, lastName=Tommy, age=37, nationality=EN)<br>User(id=4, firstName=Jennifer, lastName=Linda, age=77, nationality=TR)</pre><p>5. Let’s find out age average and maximum length of firstName.</p><pre>private void test5() {<br>    System.out.println(&quot;Test 5&quot;);</pre><pre>    double averageAge = userList.stream()<br>        .mapToInt(User::getAge)<br>        .summaryStatistics()<br>        .getAverage();</pre><pre>    System.out.print(&quot;averageAge: &quot; + averageAge);</pre><pre>    int maxFirstNameLenght = userList.stream()<br>        .mapToInt((value) -&gt; {<br>            return value.getFirstName().length();<br>        })<br>        .summaryStatistics()<br>        .getMax();</pre><pre>    System.out.println(&quot; maxFirstNameLenght: &quot; + maxFirstNameLenght);<br>}</pre><p>Output is;</p><pre>Test 5<br>averageAge: 29.0 maxFirstNameLenght: 8</pre><p>6. Check if all ages greater than 6.</p><pre>private void test6() {<br>    System.out.println(&quot;Test 6&quot;);</pre><pre>    boolean isAllAgesGreaterThan6 = userList.stream()<br>                .allMatch(user -&gt; user.getAge() &gt; 6);</pre><pre>    System.out.println(&quot;isAllAgesGreaterThan6: &quot; +     isAllAgesGreaterThan6);<br>}</pre><p>Output is;</p><pre>Test 6<br>isAllAgesGreaterThan6: true</pre><p>7. Check if any of firstName property’s first character is S.</p><pre>private void test7() {<br>    System.out.println(&quot;Test 7&quot;);<br>    boolean isFirstCharS = userList.stream()<br>        .anyMatch(user -&gt; user.getFirstName().charAt(0) == &#39;S&#39;);</pre><pre>    System.out.println(&quot;isFirstCharS &quot; + isFirstCharS);<br>}</pre><p>Output is;</p><pre>Test 7<br>isFirstCharS: true</pre><p>8. Repackage the returned Collection object to another.</p><pre>private void test8() {<br>    System.out.println(&quot;Test 8&quot;);</pre><pre>    List&lt;User&gt; list = userList.stream()<br>                .collect(Collectors.toList());</pre><pre>    Set&lt;User&gt; set = userList.stream()<br>                .collect(Collectors.toSet());</pre><pre>    List&lt;User&gt; linkedList = userList.stream()<br>                .collect(Collectors.toCollection(LinkedList::new));</pre><pre>    Map&lt;Long, User&gt; map = userList.stream()<br>                .collect(Collectors.toMap(user -&gt; user.getId(), user -&gt; user));<br>}</pre><p>9. Count different nationalities on the list.</p><pre>private void test9() {<br>    long countDifferentNationalites = userList.stream()<br>                .map(User::getNationality)<br>                .distinct()<br>                .count();</pre><pre>    System.out.println(&quot;countDifferentNationalites: &quot; + countDifferentNationalites);<br>}</pre><p>Output is;</p><pre>Test 9<br>countDifferentNationalites: 5</pre><p>10. Let’s drop out User whose firstName`s first character is M letter and is older than 10.</p><pre>private void test10() {<br>    System.out.println(&quot;Test 10&quot;);</pre><pre>userList.stream()<br>            .filter(p -&gt; (p.getFirstName().charAt(0) != &#39;M&#39;))<br>            .filter(p -&gt; (p.getAge() &gt; 10))<br>            .collect(Collectors.toList())<br>            .forEach(System.out::println);<br>}</pre><p>Output is;</p><pre>Test 10<br>User(id=4, firstName=Jennifer, lastName=Linda, age=77, nationality=TR)<br>User(id=5, firstName=William, lastName=Elizabeth, age=23, nationality=US)<br>User(id=6, firstName=Sue, lastName=Jackson, age=11, nationality=IT)</pre><p>To sum up, Java Stream is not a data structure that stores elements; instead, it conveys elements from a source such as a data structure through a pipeline of computational operations. An operation on a Java Stream produces a return value but does not modify its original source.</p><p>All sample source codes are in the <a href="https://github.com/meteergin/medium-java-streams">GitHub</a> repository. Thank you for reading the article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f4444fde921" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>