{"id":268467,"date":"2015-11-18T16:44:11","date_gmt":"2015-11-18T13:44:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=268467"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=268467","title":{"rendered":"\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 Java \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 4. Java Stream API"},"content":{"rendered":"<p>       <a href=\"http:\/\/habrahabr.ru\/post\/270383\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0b7\/b18\/760\/0b7b1876026c4aa78b926fe5a9027c72.jpg\"\/><\/a><\/p>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e Java 8 \u0432\u044b\u0448\u043b\u0430 \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0432\u043d\u043e, \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0435\u0451 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0441 Java 7 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 Java 6, \u043a\u043e\u0433\u043e-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 GWT, \u043a\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043f\u043e\u0434 Android \u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u044f\u043c\u0431\u0434 \u0438 Stream Api. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u043d\u0430\u043d\u0438\u0435 \u043b\u044f\u043c\u0431\u0434 \u0438 Stream Api \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 Java \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445, \u043d\u0443 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Java 8. \u042f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u043f\u043e Stream Api \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0441 \u043d\u043e\u0432\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c. \u0417\u043d\u0430\u043d\u0438\u044f \u043b\u044f\u043c\u0431\u0434 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f (\u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e), \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043d\u0438\u044f Java \u0438 \u0432\u044b\u0448\u0435. <\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430, \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c Java Stream Api. \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u0430\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Stream Api<\/b><\/p>\n<div class=\"spoiler_text\">Stream API \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e stream \u0432 Java 8 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  Stream Api \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0438\u043b\u0435 SQL, \u0442\u043e \u0435\u0441\u043b\u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0440\u0435\u0448\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:   <\/p>\n<pre><code class=\"java\">        Integer sumOddOld = 0;          for(Integer i: collection) {             if(i % 2 != 0) {                 sumOddOld += i;             }         } <\/code><\/pre>\n<p>  \u0422\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream Api \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435:   <\/p>\n<pre><code class=\"java\">       Integer sumOdd = collection.stream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0); <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, Stream Api \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043b\u0438\u0448\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0432 stream() \u043d\u0430 parallelStream() \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0442.\u0435.   <\/p>\n<pre><code class=\"java\">       Integer sumOdd = collection.parallelStream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0); <\/code><\/pre>\n<p>  \u0423\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c, \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0439, \u0440\u0438\u0441\u043a\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u0442.\u043f.   <\/div>\n<\/div>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0447\u0430\u043b\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 stream \u0432 Java 8.<\/p>\n<h2><b>I. \u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u043e\u0432<\/b><\/h2>\n<p>  \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c   <\/p>\n<table>\n<tr>\n<th width=\"170\">\u0421\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u0430<\/th>\n<th width=\"180\">\u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f<\/th>\n<th>\u041f\u0440\u0438\u043c\u0435\u0440<\/th>\n<\/tr>\n<tr>\n<td>1. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <\/td>\n<td>collection.<b>stream<\/b>()<\/td>\n<td>\n<pre><code class=\"java\">Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;);         Stream&lt;String&gt; streamFromCollection = collection.stream(); <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>2. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/td>\n<td><b>Stream.of<\/b>(<i>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u04351<\/i>,\u2026 <i>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435N<\/i>)<\/td>\n<td>\n<pre><code class=\"java\">Stream&lt;String&gt; streamFromValues = Stream.of(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;); <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430<\/td>\n<td><b>Arrays.stream<\/b>(<i>\u043c\u0430\u0441\u0441\u0438\u0432<\/i>)<\/td>\n<td>\n<pre><code class=\"java\">String[] array = {&quot;a1&quot;,&quot;a2&quot;,&quot;a3&quot;};                       Stream&lt;String&gt; streamFromArrays = Arrays.stream(array); <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>4. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 (\u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0441\u0442\u0440\u0438\u043c\u0435)<\/td>\n<td><b>Files.lines<\/b>(<i>\u043f\u0443\u0442\u044c_\u043a_\u0444\u0430\u0439\u043b\u0443<\/i>)<\/td>\n<td>\n<pre><code class=\"java\">Stream&lt;String&gt; streamFromFiles = Files.lines(Paths.get(&quot;file.txt&quot;)) <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>5. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438<\/td>\n<td>\u00ab\u0441\u0442\u0440\u043e\u043a\u0430\u00bb.<b>chars<\/b>()<\/td>\n<td>\n<pre><code class=\"java\">IntStream streamFromString = &quot;123&quot;.chars() <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>6. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.builder<\/td>\n<td>Stream.<b>builder<\/b>().<b>add<\/b>(&#8230;)&#8230;.<b>build<\/b>()<\/td>\n<td>\n<pre><code class=\"java\">Stream.builder().add(&quot;a1&quot;).add(&quot;a2&quot;).add(&quot;a3&quot;).build() <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>7. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>collection.<b>parallelStream<\/b>()<\/td>\n<td>\n<pre><code class=\"java\">Stream&lt;String&gt; stream = collection.parallelStream(); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<td>8. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.iterate   <\/td>\n<td><b>Stream.iterate<\/b>(<i>\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435_\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/i>, <i>\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435_\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438<\/i>)<\/td>\n<td>\n<pre><code class=\"java\">Stream&lt;Integer&gt; streamFromIterate = Stream.iterate(1, n -&gt; n + 1) <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>9. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.generate<\/td>\n<td><b>Stream.generate<\/b>(<i>\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435_\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438<\/i>)<\/td>\n<td>\n<pre><code class=\"java\">Stream&lt;String&gt; streamFromGenerate = Stream.generate(() -&gt; &quot;a1&quot;) <\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0434\u0432\u0443\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u0430, \u0432\u0441\u0435 \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u043e\u0432, \u0432 iterate \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e, \u0442\u043e \u0435\u0441\u0442\u044c Stream.iterate(1, n -&gt; n + 1) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 1, 2, 3, 4,\u2026 N. Stream.generate \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0445 \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u00aba1\u00bb.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043b\u044f\u043c\u0431\u0434\u044b<\/b><\/p>\n<div class=\"spoiler_text\"> \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 n -&gt; n + 1, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f Integer func(Integer n) { return n+1;}, \u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 () -&gt; \u00aba1\u00bb \u0430\u043d\u0430\u043b\u043e\u0433 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f String func() { return \u00aba1\u00bb;} \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b\u0445 \u0432 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.   <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/BuildTests.java\">github<\/a>&#8216;e  <\/p>\n<pre><code class=\"java\">        System.out.println(&quot;Test buildStream start&quot;);          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439         Stream&lt;String&gt; streamFromValues = Stream.of(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;);         System.out.println(&quot;streamFromValues = &quot; + streamFromValues.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromValues = [a1, a2, a3]          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430         String[] array = {&quot;a1&quot;,&quot;a2&quot;,&quot;a3&quot;};         Stream&lt;String&gt; streamFromArrays = Arrays.stream(array);         System.out.println(&quot;streamFromArrays = &quot; + streamFromArrays.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromArrays = [a1, a2, a3]          Stream&lt;String&gt; streamFromArrays1 = Stream.of(array);         System.out.println(&quot;streamFromArrays1 = &quot; + streamFromArrays1.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromArrays = [a1, a2, a3]          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 (\u043a\u0430\u0436\u0434\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0432 \u0441\u0442\u0440\u0438\u043c\u0435)         File file = new File(&quot;1.tmp&quot;);         file.deleteOnExit();         PrintWriter out = new PrintWriter(file);         out.println(&quot;a1&quot;);         out.println(&quot;a2&quot;);         out.println(&quot;a3&quot;);         out.close();          Stream&lt;String&gt; streamFromFiles = Files.lines(Paths.get(file.getAbsolutePath()));         System.out.println(&quot;streamFromFiles = &quot; + streamFromFiles.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromFiles = [a1, a2, a3]          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;);         Stream&lt;String&gt; streamFromCollection = collection.stream();         System.out.println(&quot;streamFromCollection = &quot; + streamFromCollection.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromCollection = [a1, a2, a3]          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438         IntStream streamFromString = &quot;123&quot;.chars();         System.out.print(&quot;streamFromString = &quot;);         streamFromString.forEach((e)-&gt;System.out.print(e + &quot; , &quot;)); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromString = 49 , 50 , 51 ,         System.out.println();          \/\/ \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.builder         Stream.Builder&lt;String&gt; builder = Stream.builder();         Stream&lt;String&gt; streamFromBuilder = builder.add(&quot;a1&quot;).add(&quot;a2&quot;).add(&quot;a3&quot;).build();         System.out.println(&quot;streamFromBuilder = &quot; + streamFromBuilder.collect((Collectors.toList()))); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromFiles = [a1, a2, a3]          \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u043e\u0432         \/\/ \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.iterate         Stream&lt;Integer&gt; streamFromIterate = Stream.iterate(1, n -&gt; n + 2);         System.out.println(&quot;streamFromIterate = &quot; + streamFromIterate.limit(3).collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromIterate = [1, 3, 5]          \/\/ \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream.generate         Stream&lt;String&gt; streamFromGenerate = Stream.generate(() -&gt; &quot;a1&quot;);         System.out.println(&quot;streamFromGenerate = &quot; + streamFromGenerate.limit(3).collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamFromGenerate = [a1, a1, a1]          \/\/ \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u0438\u043c         Stream&lt;String&gt; streamEmpty = Stream.empty();         System.out.println(&quot;streamEmpty = &quot; + streamEmpty.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 streamEmpty = []          \/\/ \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         Stream&lt;String&gt; parallelStream = collection.parallelStream();         System.out.println(&quot;parallelStream = &quot; + parallelStream.collect(Collectors.toList())); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 parallelStream = [a1, a2, a3] <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h2><b>II. \u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u0430\u043c\u0438<\/b><\/h2>\n<p>  Java Stream API \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u0432\u0430 \u0432\u0438\u0434\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432: <br \/>  1. \u041a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0435 \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 stream, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043a\u0430\u043a builder, <br \/>  2. \u0422\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u043e\u0431\u044a\u0435\u043a\u0442\u044b, Optional \u0438 \u0442.\u0434.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e \u0442\u043e\u043c \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0435 \u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/b><\/p>\n<div class=\"spoiler_text\"><b>\u041e\u0431\u0449\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/b>: \u0443 stream&#8217;a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043e\u0434\u0438\u043d \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e \u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 Thread \u0438\u043b\u0438 Runnable, \u043d\u043e \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0443 \u043d\u0435\u0433\u043e start.<\/p>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c, \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 Select&#8217;\u043e\u0432 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0438\u0442\u043e\u0433\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 collection.stream().filter((s) -&gt; s.contains(\u00ab1\u00bb)).skip(2).findFirst(), filter \u0438 skip \u2014 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0435, \u0430 findFirst \u2014 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Optional \u0438 \u044d\u0442\u043e \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e stream&#8217;\u043e\u043c.  <\/div>\n<\/div>\n<h3><b>2.1 \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u0430\u043c\u0438<\/b><\/h3>\n<table>\n<tr>\n<th width=\"140\">\u041c\u0435\u0442\u043e\u0434 stream<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<th width=\"420\">\u041f\u0440\u0438\u043c\u0435\u0440<\/th>\n<\/tr>\n<tr>\n<td><b>filter<\/b><\/td>\n<td>\u041e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044e<\/td>\n<td>collection.stream().filter(\u00aba1\u00bb::equals).count()<\/td>\n<\/tr>\n<tr>\n<td><b>skip<\/b><\/td>\n<td>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c N \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/td>\n<td>collection.stream().skip(collection.size() \u2014 1).findFirst().orElse(\u00ab1\u00bb)<\/td>\n<\/tr>\n<tr>\n<td><b>distinct<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u0438\u043c \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 (\u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 equals)<\/td>\n<td>collection.stream().distinct().collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>map<\/b><\/td>\n<td>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>collection.stream().map((s) -&gt; s + &quot;_1&quot;).collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>peek<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0442\u0440\u0438\u043c, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>collection.stream().map(String::toUpperCase).peek((e) -&gt; System.out.print(&quot;,&quot; + e)).<br \/>   collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>limit<\/b><\/td>\n<td>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/td>\n<td>collection.stream().limit(2).collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>sorted<\/b><\/td>\n<td>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u0432 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043b\u0438\u0431\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u044f Comparator<\/td>\n<td>collection.stream().sorted().collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>mapToInt<\/b>, <br \/>  <b>mapToDouble<\/b>, <br \/>  <b>mapToLong<\/b><\/td>\n<td>\u0410\u043d\u0430\u043b\u043e\u0433 map, \u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0438\u043c (\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u0438\u0437 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432)<\/td>\n<td>collection.stream().mapToInt((s) -&gt; Integer.parseInt(s)).toArray()<\/td>\n<\/tr>\n<tr>\n<td><b>flatMap<\/b>,<br \/>  <b>flatMapToInt<\/b>,<br \/>  <b>flatMapToDouble<\/b>,<br \/>  <b>flatMapToLong<\/b><\/td>\n<td>\u041f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 map, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e<\/td>\n<td>collection.stream().flatMap((p) -&gt; Arrays.asList(p.split(&quot;,&quot;)).stream()).toArray(String[]::new)<\/td>\n<\/tr>\n<\/table>\n<h3><b>2.2 \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u0430\u043c\u0438<\/b><\/h3>\n<p>  <\/p>\n<table>\n<tr>\n<th width=\"120\">\u041c\u0435\u0442\u043e\u0434 stream<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<th width=\"450\">\u041f\u0440\u0438\u043c\u0435\u0440<\/th>\n<\/tr>\n<tr>\n<td><b>findFirst<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u0438\u043c\u0430 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Optional)<\/td>\n<td>collection.stream().findFirst().orElse(\u00ab1\u00bb)<\/td>\n<\/tr>\n<tr>\n<td><b>findAny<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u0438\u043c\u0430 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Optional)<\/td>\n<td>collection.stream().findAny().orElse(\u00ab1\u00bb)<\/td>\n<\/tr>\n<tr>\n<td><b>collect<\/b><\/td>\n<td>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/td>\n<td>collection.stream().filter((s) -&gt; s.contains(\u00ab1\u00bb)).collect(Collectors.toList())<\/td>\n<\/tr>\n<tr>\n<td><b>count<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0442\u0440\u0438\u043c\u0435<\/td>\n<td>collection.stream().filter(\u00aba1\u00bb::equals).count()<\/td>\n<\/tr>\n<tr>\n<td><b>anyMatch<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/td>\n<td>collection.stream().anyMatch(\u00aba1\u00bb::equals)<\/td>\n<\/tr>\n<tr>\n<td><b>noneMatch<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/td>\n<td>collection.stream().noneMatch(\u00aba8\u00bb::equals)<\/td>\n<\/tr>\n<tr>\n<td><b>allMatch<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/td>\n<td>collection.stream().allMatch((s) -&gt; s.contains(\u00ab1\u00bb))<\/td>\n<\/tr>\n<tr>\n<td><b>min<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440<\/td>\n<td>collection.stream().min(String::compareTo).get()<\/td>\n<\/tr>\n<tr>\n<td><b>max<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440<\/td>\n<td>collection.stream().max(String::compareTo).get()<\/td>\n<\/tr>\n<tr>\n<td><b>forEach<\/b><\/td>\n<td>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/td>\n<td>set.stream().forEach((p) -&gt; p.append(&quot;_1&quot;));<\/td>\n<\/tr>\n<tr>\n<td><b>forEachOrdered<\/b><\/td>\n<td>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442<\/td>\n<td>list.stream().forEachOrdered((p) -&gt; p.append(&quot;_new&quot;));<\/td>\n<\/tr>\n<tr>\n<td><b>toArray<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>collection.stream().map(String::toUpperCase).toArray(String[]::new);<\/td>\n<\/tr>\n<\/table>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b findFirst, findAny, anyMatch \u044d\u0442\u043e short-circuiting \u043c\u0435\u0442\u043e\u0434\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0431\u0445\u043e\u0434 \u0441\u0442\u0440\u0438\u043c\u043e\u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u0430 \u043d\u0435 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c.<\/p>\n<h3><b>2.3 \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u043e\u0432<\/b><\/h3>\n<p>  <\/p>\n<table>\n<tr>\n<th width=\"100\">\u041c\u0435\u0442\u043e\u0434 stream<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<th width=\"450\">\u041f\u0440\u0438\u043c\u0435\u0440<\/th>\n<\/tr>\n<tr>\n<td><b>sum<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b<\/td>\n<td>collection.stream().mapToInt((s) -&gt; Integer.parseInt(s)).sum()<\/td>\n<\/tr>\n<tr>\n<td><b>average<\/b><\/td>\n<td>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b<\/td>\n<td>collection.stream().mapToInt((s) -&gt; Integer.parseInt(s)).average()<\/td>\n<\/tr>\n<tr>\n<td><b>mapToObj<\/b><\/td>\n<td>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0438\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439<\/td>\n<td>intStream.mapToObj((id) -&gt; new Key(id)).toArray()<\/td>\n<\/tr>\n<\/table>\n<h3><b>2.4 \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u0442\u0440\u0438\u043c\u043e\u0432<\/b><\/h3>\n<p>  <\/p>\n<table>\n<tr>\n<th width=\"100\">\u041c\u0435\u0442\u043e\u0434 stream<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<tr>\n<td><b>isParallel<\/b><\/td>\n<td>\u0423\u0437\u043d\u0430\u0442\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0442\u0440\u0438\u043c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c <\/td>\n<\/tr>\n<tr>\n<td><b>parallel<\/b><\/td>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u0438\u043c \u0443\u0436\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439, \u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f<\/td>\n<\/tr>\n<tr>\n<td><b>sequential<\/b><\/td>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u0438\u043c \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f<\/td>\n<\/tr>\n<\/table>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e, \u043c\u0435\u0442\u043e\u0434\u043e\u0432 parallel \u0438 sequential \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0430 \u043a\u0430\u043a\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438. \u0422\u0430\u043a \u0436\u0435 \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0442\u043e \u0435\u0441\u0442\u044c:   <\/p>\n<pre><code class=\"java\">collection.stream(). peek(...). \/\/ \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u0430 parallel(). map(...). \/\/ \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, sequential(). reduce(...) \/\/ \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u0430  <\/code><\/pre>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u0438\u043c\u044b \u0434\u043b\u044f \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043e\u043b\u0433\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u0430\u0437\u044b, \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439), \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u0438\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 c \u043e\u0434\u043d\u0438\u043c \u043f\u0443\u043b\u043e\u043c fork\/join \u0438 \u0442\u0430\u043a\u0438\u0435 \u0434\u043e\u043b\u0433\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0438\u043c\u043e\u0432 \u0432 JVM. <\/p>\n<h2><b>III. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0441\u0442\u0440\u0438\u043c\u043e\u0432<\/b><\/h2>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<h3><b>3.1 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f filter, findFirst, findAny, skip, limit \u0438 count<\/b><\/h3>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a Arrays.asList(\u00aba1\u00bb, \u00aba2\u00bb, \u00aba3\u00bb, \u00aba1\u00bb), \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434\u044b filter, findFirst, findAny, skip \u0438 count:  <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u00aba1\u00bb<\/td>\n<td>collection.stream().filter(\u00aba1\u00bb::equals).count()<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 0, \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043f\u0443\u0441\u0442\u0430<\/td>\n<td>collection.stream().findFirst().orElse(0)<\/td>\n<td>a1<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u00abempty\u00bb, \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043f\u0443\u0441\u0442\u0430<\/td>\n<td>collection.stream().skip(collection.size() \u2014 1).findAny().orElse(\u00abempty\u00bb)<\/td>\n<td>a1<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0440\u0430\u0432\u043d\u044b\u0439 \u00aba3\u00bb \u0438\u043b\u0438 \u043a\u0438\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443<\/td>\n<td>collection.stream().filter(\u00aba3\u00bb::equals).findFirst().get()<\/td>\n<td>a3<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0440\u0435\u0442\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443<\/td>\n<td>collection.stream().skip(2).findFirst().get()<\/td>\n<td>a3<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e<\/td>\n<td>collection.stream().skip(1).limit(2).toArray()<\/td>\n<td>[a2, a3]<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443<\/td>\n<td>collection.stream().filter((s) -&gt; s.contains(\u00ab1\u00bb)).collect(Collectors.toList())<\/td>\n<td>[a1, a1]<\/td>\n<\/tr>\n<\/table>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b findFirst \u0438 findAny \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f Optional, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0432 Java 8, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c NullPointerException. \u041c\u0435\u0442\u043e\u0434 filter \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043b\u0438\u0448\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u043c\u0435\u0442\u043e\u0434 skip \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043b\u044f\u043c\u0431\u0434\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u00aba3\u00bb::equals \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 boolean func(s) { return \u00aba3\u00bb.equals(s);}, \u0430 (s) -&gt; s.contains(\u00ab1\u00bb) \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 boolean func(s) { return s.contains(\u00ab1\u00bb);} \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b\u0445 \u0432 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.  <\/div>\n<\/div>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441 People (\u0441 \u043f\u043e\u043b\u044f\u043c\u0438 name \u2014 \u0438\u043c\u044f, age \u2014 \u0432\u043e\u0437\u0440\u0430\u0441\u0442, sex \u2014 \u043f\u043e\u043b), \u0432\u0438\u0434\u0430 Arrays.asList( new People(\u00ab\u0412\u0430\u0441\u044f\u00bb, 16, Sex.MAN), new People(\u00ab\u041f\u0435\u0442\u044f\u00bb, 23, Sex.MAN), new People(\u00ab\u0415\u043b\u0435\u043d\u0430\u00bb, 42, Sex.WOMEN), new People(\u00ab\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447\u00bb, 69, Sex.MAN)). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c: <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0443\u0436\u0447\u0438\u043d-\u0432\u043e\u0435\u043d\u043d\u043e\u043e\u0431\u044f\u0437\u0430\u043d\u043d\u044b\u0445 (\u043e\u0442 18 \u0434\u043e 27 \u043b\u0435\u0442)<\/td>\n<td>peoples.stream().filter((p)-&gt; p.getAge() &gt;= 18 &#038;&#038; p.getAge() &lt; 27<br \/>   &#038;&#038; p.getSex() == Sex.MAN).collect(Collectors.toList())<\/td>\n<td>[{name=&#8217;\u041f\u0435\u0442\u044f&#8217;, age=23, sex=MAN}]<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u0441\u0440\u0435\u0434\u0438 \u043c\u0443\u0436\u0447\u0438\u043d<\/td>\n<td>peoples.stream().filter((p) -&gt; p.getSex() == Sex.MAN).<br \/>   mapToInt(People::getAge).average().getAsDouble()<\/td>\n<td>36.0<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u0431\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 (\u0442.\u0435. \u043e\u0442 18 \u043b\u0435\u0442 \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0447\u0442\u043e \u0436\u0435\u043d\u0449\u0438\u043d\u044b \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u0432 55 \u043b\u0435\u0442, \u0430 \u043c\u0443\u0436\u0447\u0438\u043d\u0430 \u0432 60)<\/td>\n<td>peoples.stream().filter((p) -&gt; p.getAge() &gt;= 18).filter(<br \/>   (p) -&gt; (p.getSex() == Sex.WOMEN &#038;&#038; p.getAge() &lt; 55) || (p.getSex() == Sex.MAN &#038;&#038; p.getAge() &lt; 60)).count()<\/td>\n<td>2<\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 github&#8217;e: <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/FiterAndCountTests.java\">\u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/a> \u0438 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/LimitAndSkipTests.java\">\u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043b\u0430\u0441\u0441<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ filter - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 stream, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430     \/\/ count - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0442\u0440\u0438\u043c\u0435     \/\/ collect - \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 stream \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445     \/\/ mapToInt - \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0438\u043c (\u0441\u0442\u0440\u0438\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0447\u0438\u0441\u043b\u0430)     private static void testFilterAndCount() {         System.out.println();         System.out.println(&quot;Test filter and count start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);         Collection&lt;People&gt; peoples = Arrays.asList(                 new People(&quot;\u0412\u0430\u0441\u044f&quot;, 16, Sex.MAN),                 new People(&quot;\u041f\u0435\u0442\u044f&quot;, 23, Sex.MAN),                 new People(&quot;\u0415\u043b\u0435\u043d\u0430&quot;, 42, Sex.WOMEN),                 new People(&quot;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&quot;, 69, Sex.MAN)         );          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430         long count = collection.stream().filter(&quot;a1&quot;::equals).count();         System.out.println(&quot;count = &quot; + count); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 count = 2          \/\/ \u0412\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443         List&lt;String&gt; select = collection.stream().filter((s) -&gt; s.contains(&quot;1&quot;)).collect(Collectors.toList());         System.out.println(&quot;select = &quot; + select); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 select = [a1, a1]          \/\/ \u0412\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0443\u0436\u0447\u0438\u043d-\u0432\u043e\u0435\u043d\u043d\u043e\u043e\u0431\u044f\u0437\u0430\u043d\u043d\u044b\u0445          List&lt;People&gt; militaryService = peoples.stream().filter((p)-&gt; p.getAge() &gt;= 18 && p.getAge() &lt; 27                 && p.getSex() == Sex.MAN).collect(Collectors.toList());         System.out.println(&quot;militaryService = &quot; + militaryService); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 militaryService = [{name='\u041f\u0435\u0442\u044f', age=23, sex=MAN}]          \/\/ \u041d\u0430\u0439\u0442\u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u0441\u0440\u0435\u0434\u0438 \u043c\u0443\u0436\u0447\u0438\u043d         double manAverageAge = peoples.stream().filter((p) -&gt; p.getSex() == Sex.MAN).                 mapToInt(People::getAge).average().getAsDouble();         System.out.println(&quot;manAverageAge = &quot; + manAverageAge); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 manAverageAge = 36.0          \/\/ \u041d\u0430\u0439\u0442\u0438 \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 (\u0442.\u0435. \u043e\u0442 18 \u043b\u0435\u0442 \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0447\u0442\u043e \u0436\u0435\u043d\u0449\u0438\u043d\u044b \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u0432 55 \u043b\u0435\u0442, \u0430 \u043c\u0443\u0436\u0447\u0438\u043d\u0430 \u0432 60)         long peopleHowCanWork = peoples.stream().filter((p) -&gt; p.getAge() &gt;= 18).filter(                 (p) -&gt; (p.getSex() == Sex.WOMEN && p.getAge() &lt; 55) || (p.getSex() == Sex.MAN && p.getAge() &lt; 60)).count();         System.out.println(&quot;peopleHowCanWork = &quot; + peopleHowCanWork); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 manAverageAge = 2      }     \/\/ findFirst - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 Optional \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u0438\u043c\u0430     \/\/ skip - \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 N \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u0433\u0434\u0435 N \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043c\u0435\u0442\u043e\u0434\u0430)     \/\/ collect \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 stream \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445     private static void testFindFirstSkipCount() {         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);          System.out.println(&quot;Test findFirst and skip start&quot;);         \/\/ \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         String first = collection.stream().findFirst().orElse(&quot;1&quot;);         System.out.println(&quot;first = &quot; + first); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 first = a1          \/\/ \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         String last = collection.stream().skip(collection.size() - 1).findAny().orElse(&quot;1&quot;);         System.out.println(&quot;last = &quot; + last ); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 last = a1          \/\/ \u043d\u0430\u0439\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         String find = collection.stream().filter(&quot;a3&quot;::equals).findFirst().get();         System.out.println(&quot;find = &quot; + find); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 find = a3          \/\/ \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0440\u0435\u0442\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443         String third = collection.stream().skip(2).findFirst().get();         System.out.println(&quot;third = &quot; + third); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 third = a3          System.out.println();         System.out.println(&quot;Test collect start&quot;);         \/\/ \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443         List&lt;String&gt; select = collection.stream().filter((s) -&gt; s.contains(&quot;1&quot;)).collect(Collectors.toList());         System.out.println(&quot;select = &quot; + select); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 select = [a1, a1]     }      \/\/ \u041c\u0435\u0442\u043e\u0434 Limit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     private static void testLimit() {         System.out.println();         System.out.println(&quot;Test limit start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         List&lt;String&gt; limit = collection.stream().limit(2).collect(Collectors.toList());         System.out.println(&quot;limit = &quot; + limit); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 limit = [a1, a2]          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e         List&lt;String&gt; fromTo = collection.stream().skip(1).limit(2).collect(Collectors.toList());         System.out.println(&quot;fromTo = &quot; + fromTo); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 fromTo = [a2, a3]          \/\/ \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         String last = collection.stream().skip(collection.size() - 1).findAny().orElse(&quot;1&quot;);         System.out.println(&quot;last = &quot; + last ); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 last = a1     }      private enum Sex {         MAN,         WOMEN     }      private static class People {         private final String name;         private final Integer age;         private final Sex sex;          public People(String name, Integer age, Sex sex) {             this.name = name;             this.age = age;             this.sex = sex;         }          public String getName() {             return name;         }          public Integer getAge() {             return age;         }          public Sex getSex() {             return sex;         }          @Override         public String toString() {             return &quot;{&quot; +                     &quot;name='&quot; + name + '\\'' +                     &quot;, age=&quot; + age +                     &quot;, sex=&quot; + sex +                     '}';         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.2 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f distinct<\/b><\/h3>\n<p>  \u041c\u0435\u0442\u043e\u0434 distinct \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 stream \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043b\u044f \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 list) \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d, \u0434\u043b\u044f \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u2014 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 Collection ordered = Arrays.asList(\u00aba1\u00bb, \u00aba2\u00bb, \u00aba2\u00bb, \u00aba3\u00bb, \u00aba1\u00bb, \u00aba2\u00bb, \u00aba2\u00bb) \u0438 Collection nonOrdered = new HashSet&lt;&gt;(ordered).  <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"150\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u0438\u0437 \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>nonOrdered.stream().distinct().collect(Collectors.toList())<\/td>\n<td>[a1, a2, a3] \u2014 <br \/>  \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u0438\u0437 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430<\/td>\n<td>ordered.stream().distinct().collect(Collectors.toList());<\/td>\n<td>[a1, a2, a3] \u2014 <br \/>  \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/td>\n<\/tr>\n<\/table>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/DistinctTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">\/\/ \u041c\u0435\u0442\u043e\u0434 distinct \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 stream \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043b\u044f \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 list) \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d , \u0434\u043b\u044f \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u043e\u0433\u043e - \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f     \/\/ \u041c\u0435\u0442\u043e\u0434 collect \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 stream \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445     private static void testDistinct() {         System.out.println();         System.out.println(&quot;Test distinct start&quot;);         Collection&lt;String&gt; ordered = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;, &quot;a2&quot;, &quot;a2&quot;);         Collection&lt;String&gt; nonOrdered = new HashSet&lt;&gt;(ordered);          \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432         List&lt;String&gt; distinct = nonOrdered.stream().distinct().collect(Collectors.toList());         System.out.println(&quot;distinct = &quot; + distinct); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 distinct = [a1, a2, a3] - \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f          List&lt;String&gt; distinctOrdered = ordered.stream().distinct().collect(Collectors.toList());         System.out.println(&quot;distinctOrdered = &quot; + distinctOrdered); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 distinct = [a1, a2, a3] - \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.3 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Match \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (anyMatch, allMatch, noneMatch)<\/b><\/h3>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a Arrays.asList(\u00aba1\u00bb, \u00aba2\u00bb, \u00aba3\u00bb, \u00aba1\u00bb), \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Match \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u0438\u043d \u00aba1\u00bb \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/td>\n<td>collection.stream().anyMatch(\u00aba1\u00bb::equals)<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u0438\u043d \u00aba8\u00bb \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/td>\n<td>collection.stream().anyMatch(\u00aba8\u00bb::equals)<\/td>\n<td>false<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b \u00ab1\u00bb \u0443 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/td>\n<td>collection.stream().allMatch((s) -&gt; s.contains(\u00ab1\u00bb))<\/td>\n<td>false<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u00aba7\u00bb \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/td>\n<td>collection.stream().noneMatch(\u00aba7\u00bb::equals)<\/td>\n<td>true<\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/FindAndMatchTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 anyMatch - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430     \/\/ \u041c\u0435\u0442\u043e\u0434 noneMatch - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430     \/\/ \u041c\u0435\u0442\u043e\u0434 allMatch - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     private static void testMatch() {         System.out.println();         System.out.println(&quot;Test anyMatch, allMatch, noneMatch  start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);          \/\/ \u043d\u0430\u0439\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         boolean isAnyOneTrue = collection.stream().anyMatch(&quot;a1&quot;::equals);         System.out.println(&quot;anyOneTrue &quot; + isAnyOneTrue); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 true         boolean isAnyOneFalse = collection.stream().anyMatch(&quot;a8&quot;::equals);         System.out.println(&quot;anyOneFlase &quot; + isAnyOneFalse); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 false          \/\/ \u043d\u0430\u0439\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         boolean isAll = collection.stream().allMatch((s) -&gt; s.contains(&quot;1&quot;));         System.out.println(&quot;isAll &quot; + isAll); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 false          \/\/ \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e         boolean isNotEquals = collection.stream().noneMatch(&quot;a7&quot;::equals);         System.out.println(&quot;isNotEquals &quot; + isNotEquals); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 true     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.4 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Map \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (map, mapToInt, FlatMap, FlatMapToInt)<\/b><\/h3>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 collection1 = Arrays.asList(\u00aba1\u00bb, \u00aba2\u00bb, \u00aba3\u00bb, \u00aba1\u00bb) \u0438 collection2 = Arrays.asList(\u00ab1,2,0\u00bb, \u00ab4,5\u00bb), \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 map \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c &quot;_1&quot; \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/td>\n<td>collection1.stream().map((s) -&gt; s + &quot;_1&quot;).collect(Collectors.toList())<\/td>\n<td>[a1_1, a2_1, a3_1, a1_1]<\/td>\n<\/tr>\n<tr>\n<td>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0438\u0441\u0435\u043b (int[]) <\/td>\n<td>collection.stream().mapToInt((s) -&gt; Integer.parseInt(s.substring(1))).toArray()<\/td>\n<td>[1, 2, 3, 1]<\/td>\n<\/tr>\n<tr>\n<td>\u0418\u0437 \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e \u0438\u0437 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/td>\n<td>collection.stream().flatMap((p) -&gt; Arrays.asList(p.split(&quot;,&quot;)).stream()).toArray(String[]::new)<\/td>\n<td>[1, 2, 0, 4, 5]<\/td>\n<\/tr>\n<tr>\n<td>\u0418\u0437 \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e<\/td>\n<td>collection.stream().flatMapToInt((p) -&gt; Arrays.asList(p.split(&quot;,&quot;)).stream().mapToInt(Integer::parseInt)).sum()<\/td>\n<td>12<\/td>\n<\/tr>\n<\/table>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432\u0441\u0435 map \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430 (\u043a\u043b\u0430\u0441\u0441\u0430), \u0442\u043e \u0435\u0441\u0442\u044c map \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c \u0441\u0442\u0440\u043e\u043a, \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u0430\u0442\u044c Stream \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 Integer \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043b\u044e\u0434\u0435\u0439 People, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Office, \u0433\u0434\u0435 \u044d\u0442\u0438 \u043b\u044e\u0434\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0438 \u0442.\u043f., flatMap (flatMapToInt \u0438 \u0442.\u043f.) \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u0441 \u043e\u0434\u043d\u0438\u043c, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0438\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430 (\u0441\u043c. \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430). <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/MapTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 Map \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u0443, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 stream \u0441 \u043d\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439     private static void testMap() {         System.out.println();         System.out.println(&quot;Test map start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);         \/\/ \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         List&lt;String&gt; transform = collection.stream().map((s) -&gt; s + &quot;_1&quot;).collect(Collectors.toList());         System.out.println(&quot;transform = &quot; + transform); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 transform = [a1_1, a2_1, a3_1, a1_1]          \/\/ \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0447\u0438\u0441\u043b\u0430         List&lt;Integer&gt; number = collection.stream().map((s) -&gt; Integer.parseInt(s.substring(1))).collect(Collectors.toList());         System.out.println(&quot;number = &quot; + number); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 transform = [1, 2, 3, 1]      }      \/\/ \u041c\u0435\u0442\u043e\u0434 MapToInt - \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u0443, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 stream \u0441 \u043d\u043e\u0432\u043e\u0439 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439     private static void testMapToInt() {         System.out.println();         System.out.println(&quot;Test mapToInt start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);         \/\/ \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0447\u0438\u0441\u043b\u0430         int[] number = collection.stream().mapToInt((s) -&gt; Integer.parseInt(s.substring(1))).toArray();         System.out.println(&quot;number = &quot; + Arrays.toString(number)); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 number = [1, 2, 3, 1]      }      \/\/ \u041c\u0435\u0442\u043e\u0434 FlatMap - \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 Map - \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 stream \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439     private static void testFlatMap() {         System.out.println();         System.out.println(&quot;Test flat map start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;1,2,0&quot;, &quot;4,5&quot;);         \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e \u0432 collection         String[] number = collection.stream().flatMap((p) -&gt; Arrays.asList(p.split(&quot;,&quot;)).stream()).toArray(String[]::new);         System.out.println(&quot;number = &quot; + Arrays.toString(number)); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 number = [1, 2, 0, 4, 5]     }      \/\/ \u041c\u0435\u0442\u043e\u0434 FlatMapToInt - \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 MapToInt - \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 stream \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439     private static void testFlatMapToInt() {         System.out.println();         System.out.println(&quot;Test flat map start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;1,2,0&quot;, &quot;4,5&quot;);         \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e \u0432 collection         int sum = collection.stream().flatMapToInt((p) -&gt; Arrays.asList(p.split(&quot;,&quot;)).stream().mapToInt(Integer::parseInt)).sum();         System.out.println(&quot;sum = &quot; + sum); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sum = 12     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.5 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Sorted \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/b><\/h3>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a Arrays.asList(\u00aba1\u00bb, \u00aba4\u00bb, \u00aba3\u00bb, \u00aba2\u00bb, \u00aba1\u00bb, \u00aba4\u00bb) \u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043b\u044e\u0434\u0435\u0439 \u043a\u043b\u0430\u0441\u0441\u0430 People (\u0441 \u043f\u043e\u043b\u044f\u043c\u0438 name \u2014 \u0438\u043c\u044f, age \u2014 \u0432\u043e\u0437\u0440\u0430\u0441\u0442, sex \u2014 \u043f\u043e\u043b), \u0432\u0438\u0434\u0430 Arrays.asList( new People(\u00ab\u0412\u0430\u0441\u044f\u00bb, 16, Sex.MAN), new People(\u00ab\u041f\u0435\u0442\u044f\u00bb, 23, Sex.MAN), new People(\u00ab\u0415\u043b\u0435\u043d\u0430\u00bb, 42, Sex.WOMEN), new People(\u00ab\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447\u00bb, 69, Sex.MAN)). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u0430\u043a \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c: <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"130\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443<\/td>\n<td>collection.stream().sorted().collect(Collectors.toList())<\/td>\n<td>[a1, a1, a2, a3, a4, a4]<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435<\/td>\n<td>collection.stream().sorted((o1, o2) -&gt; -o1.compareTo(o2)).collect(Collectors.toList())<\/td>\n<td>[a4, a4, a3, a2, a1, a1]<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/td>\n<td>collection.stream().sorted().distinct().collect(Collectors.toList())<\/td>\n<td>[a1, a2, a3, a4]<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/td>\n<td>collection.stream().sorted((o1, o2) -&gt; -o1.compareTo(o2)).distinct().collect(Collectors.toList())<\/td>\n<td>[a4, a3, a2, a1]<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043b\u044e\u0434\u0435\u0439 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435<\/td>\n<td>peoples.stream().sorted((o1,o2) -&gt; -o1.getName().compareTo(o2.getName())).collect(Collectors.toList())<\/td>\n<td>[{&#8216;\u041f\u0435\u0442\u044f&#8217;}, {&#8216;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&#8217;}, {&#8216;\u0415\u043b\u0435\u043d\u0430&#8217;}, {&#8216;\u0412\u0430\u0441\u044f&#8217;}]  <\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043b\u044e\u0434\u0435\u0439 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u043f\u043e\u043b\u0443, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443<\/td>\n<td>peoples.stream().sorted((o1, o2) -&gt; o1.getSex() != o2.getSex()? o1.getSex().<br \/>   compareTo(o2.getSex()): o1.getAge().compareTo(o2.getAge())).collect(Collectors.toList())<\/td>\n<td>[{&#8216;\u0412\u0430\u0441\u044f&#8217;}, {&#8216;\u041f\u0435\u0442\u044f&#8217;}, {&#8216;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&#8217;}, {&#8216;\u0415\u043b\u0435\u043d\u0430&#8217;}]<\/td>\n<\/tr>\n<\/table>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/SortedTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 Sorted \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u0432 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043b\u0438\u0431\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u044f Comparator     private static void testSorted() {         System.out.println();         System.out.println(&quot;Test sorted start&quot;);          \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a4&quot;, &quot;a3&quot;, &quot;a2&quot;, &quot;a1&quot;, &quot;a4&quot;);          \/\/ \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443         List&lt;String&gt; sorted = collection.stream().sorted().collect(Collectors.toList());         System.out.println(&quot;sorted = &quot; + sorted); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sorted = [a1, a1, a2, a3, a4, a4]          \/\/ \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b         List&lt;String&gt; sortedDistinct = collection.stream().sorted().distinct().collect(Collectors.toList());         System.out.println(&quot;sortedDistinct = &quot; + sortedDistinct); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sortedDistinct = [a1, a2, a3, a4]          \/\/ \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435         List&lt;String&gt; sortedReverse = collection.stream().sorted((o1, o2) -&gt; -o1.compareTo(o2)).collect(Collectors.toList());         System.out.println(&quot;sortedReverse = &quot; + sortedReverse); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sortedReverse = [a4, a4, a3, a2, a1, a1]          \/\/ \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435  \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b         List&lt;String&gt; distinctReverse = collection.stream().sorted((o1, o2) -&gt; -o1.compareTo(o2)).distinct().collect(Collectors.toList());         System.out.println(&quot;distinctReverse = &quot; + distinctReverse); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sortedReverse = [a4, a3, a2, a1]          \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438         \/\/ \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043b\u044e\u0434\u0435\u0439         Collection&lt;People&gt; peoples = Arrays.asList(                 new People(&quot;\u0412\u0430\u0441\u044f&quot;, 16, Sex.MAN),                 new People(&quot;\u041f\u0435\u0442\u044f&quot;, 23, Sex.MAN),                 new People(&quot;\u0415\u043b\u0435\u043d\u0430&quot;, 42, Sex.WOMEN),                 new People(&quot;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&quot;, 69, Sex.MAN)         );          \/\/ \u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435         Collection&lt;People&gt; byName = peoples.stream().sorted((o1,o2) -&gt; -o1.getName().compareTo(o2.getName())).collect(Collectors.toList());         System.out.println(&quot;byName = &quot; + byName); \/\/ byName = [{name='\u041f\u0435\u0442\u044f', age=23, sex=MAN}, {name='\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447', age=69, sex=MAN}, {name='\u0415\u043b\u0435\u043d\u0430', age=42, sex=WOMEN}, {name='\u0412\u0430\u0441\u044f', age=16, sex=MAN}]          \/\/ \u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u043f\u043e\u043b\u0443, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443         Collection&lt;People&gt; bySexAndAge = peoples.stream().sorted((o1, o2) -&gt; o1.getSex() != o2.getSex() ? o1.getSex().                 compareTo(o2.getSex()) : o1.getAge().compareTo(o2.getAge())).collect(Collectors.toList());         System.out.println(&quot;bySexAndAge = &quot; + bySexAndAge); \/\/ bySexAndAge = [{name='\u0412\u0430\u0441\u044f', age=16, sex=MAN}, {name='\u041f\u0435\u0442\u044f', age=23, sex=MAN}, {name='\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447', age=69, sex=MAN}, {name='\u0415\u043b\u0435\u043d\u0430', age=42, sex=WOMEN}]     }      private enum Sex {         MAN,         WOMEN     }      private static class People {         private final String name;         private final Integer age;         private final Sex sex;          public People(String name, Integer age, Sex sex) {             this.name = name;             this.age = age;             this.sex = sex;         }          public String getName() {             return name;         }          public Integer getAge() {             return age;         }          public Sex getSex() {             return sex;         }          @Override         public String toString() {             return &quot;{&quot; +                     &quot;name='&quot; + name + '\\'' +                     &quot;, age=&quot; + age +                     &quot;, sex=&quot; + sex +                     '}';         }          @Override         public boolean equals(Object o) {             if (this == o) return true;             if (!(o instanceof People)) return false;             People people = (People) o;             return Objects.equals(name, people.name) &&                     Objects.equals(age, people.age) &&                     Objects.equals(sex, people.sex);         }          @Override         public int hashCode() {             return Objects.hash(name, age, sex);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.6 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Max \u0438 Min \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/b><\/h3>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0434\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a Arrays.asList(\u00aba1\u00bb, \u00aba2\u00bb, \u00aba3\u00bb, \u00aba1\u00bb), \u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Peoples \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u043e Sorted \u0438 Filter \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a<\/td>\n<td>collection.stream().max(String::compareTo).get()<\/td>\n<td>a3<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a<\/td>\n<td>collection.stream().min(String::compareTo).get()<\/td>\n<td>a1<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0434\u0435\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c<\/td>\n<td>peoples.stream().max((p1, p2) -&gt; p1.getAge().compareTo(p2.getAge())).get()<\/td>\n<td>{name=&#8217;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&#8217;, age=69, sex=MAN}<\/td>\n<\/tr>\n<tr>\n<td>\u041d\u0430\u0439\u0434\u0435\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c<\/td>\n<td>peoples.stream().min((p1, p2) -&gt; p1.getAge().compareTo(p2.getAge())).get()<\/td>\n<td>{name=&#8217;\u0412\u0430\u0441\u044f&#8217;, age=16, sex=MAN}<\/td>\n<\/tr>\n<\/table>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/MaxMinTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 max \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440     \/\/ \u041c\u0435\u0442\u043e\u0434 min \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440     private static void testMinMax() {         System.out.println();         System.out.println(&quot;Test min and max start&quot;);         \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);          \/\/ \u043d\u0430\u0439\u0442\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435         String max = collection.stream().max(String::compareTo).get();         System.out.println(&quot;max &quot; + max); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 a3          \/\/ \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435         String min = collection.stream().min(String::compareTo).get();         System.out.println(&quot;min &quot; + min); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 a1          \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438          \/\/ \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043b\u044e\u0434\u0435\u0439         Collection&lt;People&gt; peoples = Arrays.asList(                 new People(&quot;\u0412\u0430\u0441\u044f&quot;, 16, Sex.MAN),                 new People(&quot;\u041f\u0435\u0442\u044f&quot;, 23, Sex.MAN),                 new People(&quot;\u0415\u043b\u0435\u043d\u0430&quot;, 42, Sex.WOMEN),                 new People(&quot;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&quot;, 69, Sex.MAN)         );          \/\/ \u043d\u0430\u0439\u0442\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c         People older = peoples.stream().max((p1, p2) -&gt; p1.getAge().compareTo(p2.getAge())).get();         System.out.println(&quot;older &quot; + older); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 {name='\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447', age=69, sex=MAN}          \/\/ \u043d\u0430\u0439\u0442\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u043e\u043c         People younger = peoples.stream().min((p1, p2) -&gt; p1.getAge().compareTo(p2.getAge())).get();         System.out.println(&quot;younger &quot; + younger); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 {name='\u0412\u0430\u0441\u044f', age=16, sex=MAN}     }       private enum Sex {         MAN,         WOMEN     }      private static class People {         private final String name;         private final Integer age;         private final Sex sex;          public People(String name, Integer age, Sex sex) {             this.name = name;             this.age = age;             this.sex = sex;         }          public String getName() {             return name;         }          public Integer getAge() {             return age;         }          public Sex getSex() {             return sex;         }          @Override         public String toString() {             return &quot;{&quot; +                     &quot;name='&quot; + name + '\\'' +                     &quot;, age=&quot; + age +                     &quot;, sex=&quot; + sex +                     '}';         }          @Override         public boolean equals(Object o) {             if (this == o) return true;             if (!(o instanceof People)) return false;             People people = (People) o;             return Objects.equals(name, people.name) &&                     Objects.equals(age, people.age) &&                     Objects.equals(sex, people.sex);         }          @Override         public int hashCode() {             return Objects.hash(name, age, sex);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.7 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f ForEach \u0438 Peek \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/b><\/h3>\n<p>  \u041e\u0431\u0435 ForEach \u0438 Peek \u043f\u043e \u0441\u0443\u0442\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e\u0436\u0435, \u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0441\u0442\u0440\u0438\u043c\u0435, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e ForEach \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0438 \u043e\u043d\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Peek \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u0430\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f: <\/p>\n<pre><code class=\"java\">        Collection&lt;StringBuilder&gt; list = Arrays.asList(new StringBuilder(&quot;a1&quot;), new StringBuilder(&quot;a2&quot;), new StringBuilder(&quot;a3&quot;)); <\/code><\/pre>\n<p>  \u0418 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 &quot;_new&quot;, \u0442\u043e \u0434\u043b\u044f ForEach \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442   <\/p>\n<pre><code class=\"java\">        list.stream().forEachOrdered((p) -&gt; p.append(&quot;_new&quot;)); \/\/ list - \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 [a1_new, a2_new, a3_new] <\/code><\/pre>\n<p>  \u0430 \u0434\u043b\u044f peek \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442    <\/p>\n<pre><code class=\"java\">  List&lt;StringBuilder&gt; newList = list.stream().peek((p) -&gt; p.append(&quot;_new&quot;)).collect(Collectors.toList()); \/\/ \u0438 list \u0438 newList \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 [a1_new, a2_new, a3_new] <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/ForEachAndPeekTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 ForEach \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c     private static void testForEach() {         System.out.println();         System.out.println(&quot;For each start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);         \/\/ \u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430         System.out.print(&quot;forEach = &quot;);         collection.stream().map(String::toUpperCase).forEach((e) -&gt; System.out.print(e + &quot;,&quot;)); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 forEach = A1,A2,A3,A1,         System.out.println();          Collection&lt;StringBuilder&gt; list = Arrays.asList(new StringBuilder(&quot;a1&quot;), new StringBuilder(&quot;a2&quot;), new StringBuilder(&quot;a3&quot;));         list.stream().forEachOrdered((p) -&gt; p.append(&quot;_new&quot;));         System.out.println(&quot;forEachOrdered = &quot; + list); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 forEachOrdered = [a1_new, a2_new, a3_new]     }      \/\/ \u041c\u0435\u0442\u043e\u0434 Peek \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0442\u0440\u0438\u043c, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430     private static void testPeek() {         System.out.println();         System.out.println(&quot;Test peek start&quot;);         Collection&lt;String&gt; collection = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a1&quot;);         \/\/ \u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0441\u0442\u0440\u0438\u043c\u0430         System.out.print(&quot;peak1 = &quot;);         List&lt;String&gt; peek = collection.stream().map(String::toUpperCase).peek((e) -&gt; System.out.print(e + &quot;,&quot;)).                 collect(Collectors.toList());         System.out.println(); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 peak1 = A1,A2,A3,A1,         System.out.println(&quot;peek2 = &quot; + peek); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 peek2 = [A1, A2, A3, A1]          Collection&lt;StringBuilder&gt; list = Arrays.asList(new StringBuilder(&quot;a1&quot;), new StringBuilder(&quot;a2&quot;), new StringBuilder(&quot;a3&quot;));         List&lt;StringBuilder&gt; newList = list.stream().peek((p) -&gt; p.append(&quot;_new&quot;)).collect(Collectors.toList());         System.out.println(&quot;newList = &quot; + newList); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 newList = [a1_new, a2_new, a3_new]     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.8 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Reduce \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/b><\/h3>\n<p>  \u041c\u0435\u0442\u043e\u0434 reduce \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0432\u0441\u0435\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0430, \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442.\u043f.), \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0441\u0442\u0440\u0438\u043c\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0432\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u043d\u0430 \u043f\u0440\u043e\u0448\u043b\u044b\u0445 \u0448\u0430\u0433\u0430\u0445 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/b>: \u0414\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0447\u0438\u0441\u0435\u043b Arrays.asList(1, 2, 3, 4, 2) \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043d\u0430\u0434 \u043d\u0438\u043c\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f reduce.<\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"90\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0447\u0438\u0441\u0435\u043b \u0438\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c 0<\/td>\n<td>collection.stream().reduce((s1, s2) -&gt; s1 + s2).orElse(0)<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0438\u043b\u0438 -1<\/td>\n<td>collection.stream().reduce(Integer::max).orElse(-1)<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u043b\u0438 0<\/td>\n<td>collection.stream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0)<\/td>\n<td>4<\/td>\n<\/tr>\n<\/table>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/ReduceTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 reduce \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0432\u0441\u0435\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0430, \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442.\u043f.)     \/\/ \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u043e Optional \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     \/\/ map - \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f \u0432 \u0434\u0440\u0443\u0433\u043e\u0439)     \/\/ mapToInt - \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0438\u043c (\u0441\u0442\u0440\u0438\u043c, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 int)     private static void testReduce() {         System.out.println();         System.out.println(&quot;Test reduce start&quot;);          \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438         Collection&lt;Integer&gt; collection = Arrays.asList(1, 2, 3, 4, 2);          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u043c\u043c\u0443         Integer sum = collection.stream().reduce((s1, s2) -&gt; s1 + s2).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer sumOld = 0; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             sumOld += i;         }         System.out.println(&quot;sum = &quot; + sum + &quot; : &quot; + sumOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sum = 12 : 12           \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c         Integer max1 = collection.stream().reduce((s1, s2) -&gt; s1 &gt; s2 ? s1 : s2).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer max2 = collection.stream().reduce(Integer::max).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Integer::max         Integer maxOld = null; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             maxOld = maxOld != null && maxOld &gt; i? maxOld: i;         }         maxOld = maxOld == null? 0 : maxOld;         System.out.println(&quot;max = &quot; + max1 + &quot; : &quot; + max2 + &quot; : &quot; + maxOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 max1 = 4 : 4 : 4          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c         Integer min = collection.stream().reduce((s1, s2) -&gt; s1 &lt; s2 ? s1 : s2).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer minOld = null; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             minOld = minOld != null && minOld &lt; i? minOld: i;         }         minOld = minOld == null? 0 : minOld;         System.out.println(&quot;min = &quot; + min+ &quot; : &quot; + minOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 min = 1 : 1          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442         Integer last = collection.stream().reduce((s1, s2) -&gt; s2).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer lastOld = null; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             lastOld = i;         }         lastOld = lastOld == null? 0 : lastOld;         System.out.println(&quot;last = &quot; + last + &quot; : &quot; + lastOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 last = 2 : 2          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 2         Integer sumMore2 = collection.stream().filter(o -&gt; o &gt; 2).reduce((s1, s2) -&gt; s1 + s2).orElse(0);     \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer sumMore2Old = 0; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             if(i &gt; 2) {                 sumMore2Old += i;             }         }         System.out.println(&quot;sumMore2 = &quot; + sumMore2 + &quot; : &quot; + sumMore2Old); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sumMore2 = 7 : 7          \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b         Integer sumOdd = collection.stream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0); \/\/ \u0447\u0435\u0440\u0435\u0437 stream Api         Integer sumOddOld = 0; \/\/ \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443         for(Integer i: collection) {             if(i % 2 != 0) {                 sumOddOld += i;             }         }         System.out.println(&quot;sumOdd = &quot; + sumOdd + &quot; : &quot; + sumOddOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sumOdd = 4 : 4          \/\/ ************ \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438          \/\/ \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043b\u044e\u0434\u0435\u0439         Collection&lt;People&gt; peoples = Arrays.asList(                 new People(&quot;\u0412\u0430\u0441\u044f&quot;, 16, Sex.MAN),                 new People(&quot;\u041f\u0435\u0442\u044f&quot;, 23, Sex.MAN),                 new People(&quot;\u0415\u043b\u0435\u043d\u0430&quot;, 42, Sex.WOMEN),                 new People(&quot;\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447&quot;, 69, Sex.MAN)         );          \/\/ \u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u043c\u0443\u0436\u0447\u0438\u043d\u0443         int oldMan = peoples.stream().filter((p) -&gt; p.getSex() == Sex.MAN).map(People::getAge).reduce((s1, s2) -&gt; s1 &gt; s2 ? s1 : s2).get();         System.out.println(&quot;oldMan = &quot; + oldMan); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 69          \/\/ \u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0431\u0443\u043a\u0430 \u0435 \u0432 \u0438\u043c\u0435\u043d\u0438         int younger = peoples.stream().filter((p) -&gt; p.getName().contains(&quot;\u0435&quot;)).mapToInt(People::getAge).reduce((s1, s2) -&gt; s1 &lt; s2 ? s1 : s2).orElse(0);         System.out.println(&quot;younger = &quot; + younger); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 23     }      private enum Sex {         MAN,         WOMEN     }      private static class People {         private final String name;         private final Integer age;         private final Sex sex;          public People(String name, Integer age, Sex sex) {             this.name = name;             this.age = age;             this.sex = sex;         }          public String getName() {             return name;         }          public Integer getAge() {             return age;         }          public Sex getSex() {             return sex;         }          @Override         public String toString() {             return &quot;{&quot; +                     &quot;name='&quot; + name + '\\'' +                     &quot;, age=&quot; + age +                     &quot;, sex=&quot; + sex +                     '}';         }          @Override         public boolean equals(Object o) {             if (this == o) return true;             if (!(o instanceof People)) return false;             People people = (People) o;             return Objects.equals(name, people.name) &&                     Objects.equals(age, people.age) &&                     Objects.equals(sex, people.sex);         }          @Override         public int hashCode() {             return Objects.hash(name, age, sex);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.9 \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f toArray \u0438 collect \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/b><\/h3>\n<p>  \u0415\u0441\u043b\u0438 \u0441 toArray \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c toArray() \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Object[], \u043b\u0438\u0431\u043e toArray(T[]::new) \u2014 \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0438\u043f\u0430 T, \u0442\u043e collect \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, map&#8217;\u0443 \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0438\u043f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 Collectors, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 List \u0431\u0443\u0434\u0435\u0442 stream.collect(Collectors.toList()). <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 Collectors:   <\/p>\n<table>\n<tr>\n<th width=\"200\">\u041c\u0435\u0442\u043e\u0434<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<tr>\n<td>toList, toCollection, toSet<\/td>\n<td>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0442\u0440\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/td>\n<\/tr>\n<tr>\n<td>toConcurrentMap, toMap<\/td>\n<td>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u0432 map<\/td>\n<\/tr>\n<tr>\n<td>averagingInt, averagingDouble, averagingLong<\/td>\n<td>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/td>\n<\/tr>\n<tr>\n<td>summingInt, summingDouble, summingLong<\/td>\n<td>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443<\/td>\n<\/tr>\n<tr>\n<td>summarizingInt, summarizingDouble, summarizingLong<\/td>\n<td>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 SummaryStatistics \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/td>\n<\/tr>\n<tr>\n<td>partitioningBy<\/td>\n<td>\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0445 \u043a\u0430\u043a Map&lt;Boolean, List&gt;<\/td>\n<\/tr>\n<tr>\n<td>groupingBy<\/td>\n<td>\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Map&lt;N, List&lt;T&gt;&gt;<\/td>\n<\/tr>\n<tr>\n<td>mapping<\/td>\n<td>\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 Collector&#8217;\u043e\u0432<\/td>\n<\/tr>\n<\/table>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 collect \u0438 toArray \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445: <br \/>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435:<\/b> \u0414\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0447\u0438\u0441\u0435\u043b Arrays.asList(1, 2, 3, 4), \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 collect \u0438 toArray \u0441 \u043d\u0435\u0439  <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"150\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/td>\n<td>numbers.stream().collect(Collectors.summingInt(((p) -&gt; p % 2 == 1? p: 0)))<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0447\u0435\u0441\u0442\u044c \u043e\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 1 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435<\/td>\n<td>numbers.stream().collect(Collectors.averagingInt((p) -&gt; p \u2014 1))<\/td>\n<td>1.5<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u0438\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0447\u0438\u0441\u043b\u0430\u043c 3 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443<\/td>\n<td>numbers.stream().collect(Collectors.summarizingInt((p) -&gt; p + 3))<\/td>\n<td>IntSummaryStatistics{count=4, sum=22, min=4, average=5.5, max=7}<\/td>\n<\/tr>\n<tr>\n<td>\u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 \u0447\u0435\u0442\u043d\u044b\u0435 \u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0435<\/td>\n<td>numbers.stream().collect(Collectors.partitioningBy((p) -&gt; p % 2 == 0))<\/td>\n<td>{false=[1, 3], true=[2, 4]}<\/td>\n<\/tr>\n<\/table>\n<p>  <b>\u0423\u0441\u043b\u043e\u0432\u0438\u0435:<\/b> \u0414\u0430\u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a Arrays.asList(\u00aba1\u00bb, \u00abb2\u00bb, \u00abc3\u00bb, \u00aba1\u00bb), \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 collect \u0438 toArray \u0441 \u043d\u0435\u0439  <\/p>\n<table>\n<tr>\n<th width=\"300\">\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/th>\n<th width=\"120\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/th>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432<\/td>\n<td>strings.stream().distinct().collect(Collectors.toList())<\/td>\n<td>[a1, b2, c3]<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u043e\u043a \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u0438 \u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435<\/td>\n<td>strings.stream().distinct().map(String::toUpperCase).toArray(String[]::new)<\/td>\n<td>{A1, B2, C3}<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c: \u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0435\u0433\u0430\u043c\u0438 &lt;b&gt;\u2026 &lt;\/b&gt;<\/td>\n<td>strings.stream().collect(Collectors.joining(&quot;: &quot;, &quot;&lt;b&gt; &quot;, &quot; &lt;\/b&gt;&quot;))<\/td>\n<td>&lt;b&gt; a1: b2: c3: a1 &lt;\/b&gt;<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0433\u0434\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u043b\u044e\u0447, \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/td>\n<td>strings.stream().distinct().collect(Collectors.toMap((p) -&gt; p.substring(0, 1), (p) -&gt; p.substring(1, 2)))<\/td>\n<td>{a=1, b=2, c=3}<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0441\u0442\u0440\u043e\u043a\u0438<\/td>\n<td>strings.stream().collect(Collectors.groupingBy((p) -&gt; p.substring(0, 1)))<\/td>\n<td>{a=[a1, a1], b=[b2], c=[c3]}<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0447\u0435\u0440\u0435\u0437 :<\/td>\n<td>strings.stream().collect(Collectors.groupingBy((p) -&gt; p.substring(0, 1), Collectors.mapping((p) -&gt; p.substring(1, 2), Collectors.joining(&quot;:&quot;))))<\/td>\n<td>{a=1:1, b=2, c=3}<\/td>\n<\/tr>\n<\/table>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/CollectAndToArrayTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">    \/\/ \u041c\u0435\u0442\u043e\u0434 collect \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 stream \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445     \/\/ \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 Collectors:     \/\/ toList, toCollection, toSet - \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0442\u0440\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430     \/\/ toConcurrentMap, toMap - \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u0432 map, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438     \/\/ averagingInt, averagingDouble, averagingLong - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     \/\/ summingInt, summingDouble, summingLong - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443     \/\/ summarizingInt, summarizingDouble, summarizingLong - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 SummaryStatistics \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438     \/\/ partitioningBy - \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0445 \u043a\u0430\u043a Map&lt;Boolean, List&gt;     \/\/ groupingBy - \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c Map&lt;N, List&lt;T&gt;&gt;, \u0433\u0434\u0435 T - \u0442\u0438\u043f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430, N - \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f     \/\/ mapping - \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 Collector'\u043e\u0432     private static void testCollect() {         System.out.println();         System.out.println(&quot;Test distinct start&quot;);          \/\/ ******** \u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438         Collection&lt;String&gt; strings = Arrays.asList(&quot;a1&quot;, &quot;b2&quot;, &quot;c3&quot;, &quot;a1&quot;);          \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432         List&lt;String&gt; distinct = strings.stream().distinct().collect(Collectors.toList());         System.out.println(&quot;distinct = &quot; + distinct); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 distinct = [a1, b2, c3]          \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a         String[] array = strings.stream().distinct().map(String::toUpperCase).toArray(String[]::new);         System.out.println(&quot;array = &quot; + Arrays.asList(array)); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 array = [A1, B2, C3]          \/\/ \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c : \u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0435\u0433\u0430\u043c\u0438 &lt;b&gt; ... &lt;\/b&gt;         String join = strings.stream().collect(Collectors.joining(&quot; : &quot;, &quot;&lt;b&gt; &quot;, &quot; &lt;\/b&gt;&quot;));         System.out.println(&quot;join = &quot; + join); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 &lt;b&gt; a1 : b2 : c3 : a1 &lt;\/b&gt;          \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0433\u0434\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u043b\u044e\u0447, \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435         Map&lt;String, String&gt; map = strings.stream().distinct().collect(Collectors.toMap((p) -&gt; p.substring(0, 1), (p) -&gt; p.substring(1, 2)));         System.out.println(&quot;map = &quot; + map); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 map = {a=1, b=2, c=3}          \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0441\u0442\u0440\u043e\u043a\u0438         Map&lt;String, List&lt;String&gt;&gt; groups = strings.stream().collect(Collectors.groupingBy((p) -&gt; p.substring(0, 1)));         System.out.println(&quot;groups = &quot; + groups); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 groups = {a=[a1, a1], b=[b2], c=[c3]}          \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 map, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0437\u044f\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0447\u0435\u0440\u0435\u0437 :         Map&lt;String, String&gt; groupJoin = strings.stream().collect(Collectors.groupingBy((p) -&gt; p.substring(0, 1), Collectors.mapping((p) -&gt; p.substring(1, 2), Collectors.joining(&quot;:&quot;))));         System.out.println(&quot;groupJoin = &quot; + groupJoin); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 groupJoin = groupJoin = {a=1\/1, b=2, c=3}          \/\/ ******** \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438         Collection&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4);          \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b         long sumOdd = numbers.stream().collect(Collectors.summingInt(((p) -&gt; p % 2 == 1 ? p : 0)));         System.out.println(&quot;sumOdd = &quot; + sumOdd); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sumEven = 4          \/\/ \u0412\u044b\u0447\u0435\u0441\u0442\u044c \u043a \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 1 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435         double average = numbers.stream().collect(Collectors.averagingInt((p) -&gt; p - 1));         System.out.println(&quot;average = &quot; + average); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 average = 1.5          \/\/ \u041f\u0440\u0438\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0447\u0438\u0441\u043b\u0430\u043c 3 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443         IntSummaryStatistics statistics = numbers.stream().collect(Collectors.summarizingInt((p) -&gt; p + 3));         System.out.println(&quot;statistics = &quot; + statistics); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 statistics = IntSummaryStatistics{count=4, sum=22, min=4, average=5.500000, max=7}          \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0447\u0435\u0440\u0435\u0437 IntSummaryStatistics         long sumEven = numbers.stream().collect(Collectors.summarizingInt((p) -&gt; p % 2 == 0 ? p : 0)).getSum();         System.out.println(&quot;sumEven = &quot; + sumEven); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 sumEven = 6          \/\/ \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 \u0447\u0435\u0442\u043d\u044b\u0435 \u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0435         Map&lt;Boolean, List&lt;Integer&gt;&gt; parts = numbers.stream().collect(Collectors.partitioningBy((p) -&gt; p % 2 == 0));         System.out.println(&quot;parts = &quot; + parts); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 parts = {false=[1, 3], true=[2, 4]}     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3><b>3.10 \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e Collector&#8217;a<\/b><\/h3>\n<p>  \u041a\u0440\u043e\u043c\u0435 Collector&#8217;\u043e\u0432 \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 Collectors \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 Collector, \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c. <\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e Collector&#8217;a: <\/p>\n<pre><code class=\"java\">Collector&lt;\u0422\u0438\u043f_\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u0422\u0438\u043f_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u0422\u0438\u043f_\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430&gt; \u0441ollector =  Collector.of(                 \u043c\u0435\u0442\u043e\u0434_\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430,                 \u043c\u0435\u0442\u043e\u0434_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u043a\u0430\u0436\u0434\u043e\u0433\u043e_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,                 \u043c\u0435\u0442\u043e\u0434_\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f_\u0434\u0432\u0443\u0445_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432,                 [\u043c\u0435\u0442\u043e\u0434_\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430]         ); <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435, \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e Collector&#8217;a \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0438 \u0438\u043b\u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 (\u043c\u0435\u0442\u043e\u0434_\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d). \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0434\u043e Java 8, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438: <\/p>\n<pre><code class=\"java\">        StringBuilder b = new StringBuilder(); \/\/ \u043c\u0435\u0442\u043e\u0434_\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430         for(String s: strings) {             b.append(s).append(&quot; , &quot;); \/\/ \u043c\u0435\u0442\u043e\u0434_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u043a\u0430\u0436\u0434\u043e\u0433\u043e_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,         }         String joinBuilderOld = b.toString(); \/\/ \u043c\u0435\u0442\u043e\u0434_\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430 <\/code><\/pre>\n<p>  \u0418 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432 Java 8<\/p>\n<pre><code class=\"java\">String joinBuilder = strings.stream().collect(    Collector.of(                 StringBuilder::new, \/\/ \u043c\u0435\u0442\u043e\u0434_\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430                 (b ,s) -&gt; b.append(s).append(&quot; , &quot;), \/\/ \u043c\u0435\u0442\u043e\u0434_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u043a\u0430\u0436\u0434\u043e\u0433\u043e_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,                 (b1, b2) -&gt; b1.append(b2).append(&quot; , &quot;), \/\/ \u043c\u0435\u0442\u043e\u0434_\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f_\u0434\u0432\u0443\u0445_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432                 StringBuilder::toString \/\/ \u043c\u0435\u0442\u043e\u0434_\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430         ) ); <\/code><\/pre>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435, \u0438\u0445 \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u043d\u043e \u0432\u043e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u0435\u0442\u043e\u0434_\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f_\u0434\u0432\u0443\u0445_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432? \u042d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Collector&#8217;a, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0440\u0438\u043c\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 (\u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0430\u0441\u0442\u0435\u0439), \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440 StringBuilder \u0438 \u043f\u043e\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c, \u0442\u043e \u043a\u043e\u0434 \u0434\u043e Java 8 \u043f\u0440\u0438 2 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code class=\"java\">        StringBuilder b1 = new StringBuilder(); \/\/ \u043c\u0435\u0442\u043e\u0434_\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430_1                 for(String s: stringsPart1) { \/\/  stringsPart1 - \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 strings             b1.append(s).append(&quot; , &quot;); \/\/ \u043c\u0435\u0442\u043e\u0434_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u043a\u0430\u0436\u0434\u043e\u0433\u043e_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,         }          StringBuilder b2 = new StringBuilder(); \/\/ \u043c\u0435\u0442\u043e\u0434_\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430_2                 for(String s: stringsPart2) { \/\/  stringsPart2 - \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 strings             b2.append(s).append(&quot; , &quot;); \/\/ \u043c\u0435\u0442\u043e\u0434_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u043a\u0430\u0436\u0434\u043e\u0433\u043e_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430,         }          StringBuilder b = b1.append(b2).append(&quot; , &quot;), \/\/ \u043c\u0435\u0442\u043e\u0434_\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f_\u0434\u0432\u0443\u0445_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432          String joinBuilderOld = b.toString(); \/\/ \u043c\u0435\u0442\u043e\u0434_\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439_\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438_\u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430 <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 Collectors.toList() \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u0441\u0442\u0440\u0438\u043c\u043e\u043c:  <\/p>\n<pre><code class=\"java\"> \/\/ \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 toList          Collector&lt;String, List&lt;String&gt;, List&lt;String&gt;&gt; toList = Collector.of(                 ArrayList::new, \/\/ \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430                 List::add, \/\/ \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430                 (l1, l2) -&gt; { l1.addAll(l2); return l1; } \/\/ \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438         ); \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u0438\u0437 \u0441\u0442\u0440\u0438\u043c\u0430         List&lt;String&gt; distinct1 = strings.stream().distinct().collect(toList); <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/blob\/master\/src\/com\/github\/vedenin\/rus\/stream_api\/CollectAndToArrayTests.java\">github&#8217;e<\/a>  <\/p>\n<pre><code class=\"java\">        \/\/ \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 Collector, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e StringBuilder         Collector&lt;String,StringBuilder, String&gt; stringBuilderCollector =  Collector.of(                 StringBuilder::new, \/\/ \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430                 (b ,s) -&gt; b.append(s).append(&quot; , &quot;), \/\/ \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430                 (b1, b2) -&gt; b1.append(b2).append(&quot; , &quot;), \/\/ \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438                 StringBuilder::toString \/\/ \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435         );         String joinBuilder = strings.stream().collect(stringBuilderCollector);         System.out.println(&quot;joinBuilder = &quot; + joinBuilder); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 joinBuilder = a1 , b2 , c3 , a1 ,          \/\/ \u0410\u043d\u0430\u043b\u043e\u0433 Collector'\u0430 \u0432\u044b\u0448\u0435 \u0441\u0442\u0438\u043b\u0435\u043c JDK7 \u0438 \u043d\u0438\u0436\u0435         StringBuilder b = new StringBuilder(); \/\/ \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430         for(String s: strings) {             b.append(s).append(&quot; , &quot;); \/\/ \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         }         String joinBuilderOld = b.toString(); \/\/ \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435         System.out.println(&quot;joinBuilderOld = &quot; + joinBuilderOld); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 joinBuilderOld = a1 , b2 , c3 , a1 ,          \/\/ \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 toList \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0431\u0435\u0437 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432         Collector&lt;String, List&lt;String&gt;, List&lt;String&gt;&gt; toList = Collector.of(                 ArrayList::new, \/\/ \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430                 List::add, \/\/ \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430                 (l1, l2) -&gt; { l1.addAll(l2); return l1; } \/\/ \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438         );         List&lt;String&gt; distinct1 = strings.stream().distinct().collect(toList);         System.out.println(&quot;distinct1 = &quot; + distinct1); \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 distinct1 = [a1, b2, c3] <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2><b>IV. \u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/b><\/h2>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u043c\u043e\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e stream api \u0431\u044b\u043b\u0430 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u0412\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0435\u0441\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/Vedenin\/java_collections_overview\/tree\/master\/src\/com\/github\/vedenin\/rus\/stream_api\">github&#8217;\u0435<\/a>, \u0443\u0434\u0430\u0447\u0438 \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>  P.S. \u0421\u043f\u0438\u0441\u043e\u043a \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e Stream Api:<br \/>  1. <a href=\"http:\/\/www.oracle.com\/technetwork\/articles\/java\/ma14-java-se-8-streams-2177646.html\">Processing Data with Java SE 8 Streams, Part 1<\/a> \u043e\u0442 Oracle,<br \/>  2. <a href=\"http:\/\/www.oracle.com\/technetwork\/articles\/java\/architect-streams-pt2-2227132.html\">Processing Data with Java SE 8 Streams, Part 2<\/a> \u043e\u0442 Oracle,<br \/>  3. <a href=\"http:\/\/prologistic.com.ua\/polnoe-rukovodstvo-po-java-8-stream.html\">\u041f\u043e\u043b\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e Java 8 Stream<\/a>        \t<\/p>\n<div class=\"polling\">\n<form action=\"\/json\/polling\/\" class=\"poll\" method=\"post\">\n<div class=\"poll_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043b\u0438 \u0432\u044b \u0443\u0436\u0435 Stream Api?<\/div>\n<p>  \t\t<input type=\"hidden\" name=\"post_id\" value=\"270383\"\/> \t\t<input type=\"hidden\" name=\"polling_question_id\" value=\"14223\"\/>  \t\t<\/p>\n<table class=\"answer\">\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69733\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69733\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69733\">\u0414\u0430, \u0443\u0436\u0435 \u0432 production<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69735\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69735\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69735\">\u0414\u0430, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69737\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69737\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69737\">\u041e\u0447\u0435\u043d\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69739\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69739\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69739\">\u041b\u0438\u0448\u044c \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69741\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69741\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69741\">\u041d\u0435\u0442, \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0441\u0442\u0430\u0440\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69743\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69743\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69743\">\u041d\u0435\u0442, \u043d\u043e \u0445\u043e\u0442\u0435\u043b \u0431\u044b<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69745\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69745\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69745\">\u041d\u0435\u0442, \u0438 \u043c\u043d\u0435 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u0435\u0442<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv69747\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"69747\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv69747\">\u042f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0438\u0448\u0443 \u043d\u0430 Java<\/label> \t\t\t\t<\/td>\n<\/tr>\n<\/table>\n<p class=\"total\">\u041d\u0438\u043a\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b. \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043d\u0435\u0442.<\/p>\n<\/p><\/form>\n<p class=\"for_users_only_msg\">\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a href=\"https:\/\/habrahabr.ru\/auth\/login\/\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/p>\n<\/p><\/div>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/270383\/\"> http:\/\/habrahabr.ru\/post\/270383\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <a href=\"http:\/\/habrahabr.ru\/post\/270383\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0b7\/b18\/760\/0b7b1876026c4aa78b926fe5a9027c72.jpg\"\/><\/a><\/p>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e Java 8 \u0432\u044b\u0448\u043b\u0430 \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0432\u043d\u043e, \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0435\u0451 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0441 Java 7 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 Java 6, \u043a\u043e\u0433\u043e-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 GWT, \u043a\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043f\u043e\u0434 Android \u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u044f\u043c\u0431\u0434 \u0438 Stream Api. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u043d\u0430\u043d\u0438\u0435 \u043b\u044f\u043c\u0431\u0434 \u0438 Stream Api \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 Java \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445, \u043d\u0443 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Java 8. \u042f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u043f\u043e Stream Api \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0441 \u043d\u043e\u0432\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c. \u0417\u043d\u0430\u043d\u0438\u044f \u043b\u044f\u043c\u0431\u0434 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f (\u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e), \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043d\u0438\u044f Java \u0438 \u0432\u044b\u0448\u0435. <\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430, \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c Java Stream Api. \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u0430\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Stream Api<\/b><\/p>\n<div class=\"spoiler_text\">Stream API \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e stream \u0432 Java 8 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  Stream Api \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0438\u043b\u0435 SQL, \u0442\u043e \u0435\u0441\u043b\u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043d\u0435\u0447\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0440\u0435\u0448\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:   <\/p>\n<pre><code class=\"java\">        Integer sumOddOld = 0;          for(Integer i: collection) {             if(i % 2 != 0) {                 sumOddOld += i;             }         } <\/code><\/pre>\n<p>  \u0422\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Stream Api \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435:   <\/p>\n<pre><code class=\"java\">       Integer sumOdd = collection.stream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0); <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, Stream Api \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043b\u0438\u0448\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0432 stream() \u043d\u0430 parallelStream() \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0442.\u0435.   <\/p>\n<pre><code class=\"java\">       Integer sumOdd = collection.parallelStream().filter(o -&gt; o % 2 != 0).reduce((s1, s2) -&gt; s1 + s2).orElse(0); <\/code><\/pre>\n<p>  \u0423\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c, \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0439, \u0440\u0438\u0441\u043a\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u0442.\u043f.   <\/div>\n<\/div>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-268467","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268467"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268467\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}