{"id":6967,"date":"2022-11-10T13:50:07","date_gmt":"2022-11-10T04:50:07","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6967"},"modified":"2022-11-10T14:17:48","modified_gmt":"2022-11-10T05:17:48","slug":"java-stream-2","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6967","title":{"rendered":"Java &#8211; Stream"},"content":{"rendered":"<h1>Java &#8211; Stream<\/h1>\n<p>Java Stream\uc758 filter(), map(), flatMap() \uc0ac\uc6a9 \ubc29\ubc95\uc744 \uc815\ub9ac\ud569\ub2c8\ub2e4.<\/p>\n<h2>\ub370\uc774\ud0c0 \uc900\ube44<\/h2>\n<pre><code class=\"language-java\">Map&lt;String, String&gt; map = new HashMap&lt;&gt;();\nmap.put(&quot;key01&quot;, &quot;value01&quot;);\nmap.put(&quot;key02&quot;, &quot;value02&quot;);\nmap.put(&quot;key03&quot;, &quot;value03&quot;);\nmap.put(&quot;key04&quot;, &quot;value04&quot;);\nmap.put(&quot;key05&quot;, &quot;value05&quot;);<\/code><\/pre>\n<h2>filter()<\/h2>\n<p>\uc870\uac74\uc5d0 \ubd80\ud569\ud558\ub294 \ub370\uc774\ud0c0\ub97c \ucd94\ucd9c\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">Optional&lt;Map.Entry&lt;String, String&gt;&gt; entry = map\n        .entrySet()\n        .stream()\n        .filter(e -&gt; e.getKey().equals(&quot;key02&quot;))\n        .findFirst();\n\nentry.ifPresent(stringStringEntry -&gt;\n        System.out.println(&quot;[key]:&quot; + stringStringEntry.getKey() + &quot;, [value]:&quot; + stringStringEntry.getValue())\n);<\/code><\/pre>\n<h2>map()<\/h2>\n<p>\uac01 \ub370\uc774\ud0c0\uc5d0 \ud568\uc218\ub97c \uc801\uc6a9\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">Optional&lt;String&gt; entry = map\n        .entrySet()\n        .stream()\n        .filter(e -&gt; e.getKey().startsWith(&quot;key&quot;))\n        .map(e -&gt; e.getValue())\n        .findFirst();\n\nentry.ifPresent(value -&gt;\n        System.out.println(&quot;[value]:&quot; + value)\n);<\/code><\/pre>\n<h2>flatMap()<\/h2>\n<p>2\ucc28\uc6d0 \ubc30\uc5f4\uc744 1\ucc28\uc6d0 \ubc30\uc5f4\ub85c \ubcc0\ud658\ud574 \uc90d\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">String[][] arrays = new String[][]{ {&quot;a1&quot;, &quot;a2&quot;}, {&quot;b1&quot;, &quot;b2&quot;}, {&quot;c1&quot;, &quot;c2&quot;, &quot;c3&quot;} };\n\nArrays\n        .stream(arrays)\n        .flatMap(Arrays::stream)\n        .filter(s-&gt; s.startsWith(&quot;a&quot;))\n        .map(String::toUpperCase).forEach(System.out::println);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java &#8211; Stream Java Stream\uc758 filter(), map(), flatMap() \uc0ac\uc6a9 \ubc29\ubc95\uc744 \uc815\ub9ac\ud569\ub2c8\ub2e4. \ub370\uc774\ud0c0 \uc900\ube44 Map&lt;String, String&gt; map = new HashMap&lt;&gt;(); map.put(&quot;key01&quot;, &quot;value01&quot;); map.put(&quot;key02&quot;, &quot;value02&quot;); map.put(&quot;key03&quot;, &quot;value03&quot;); map.put(&quot;key04&quot;, &quot;value04&quot;); map.put(&quot;key05&quot;, &quot;value05&quot;); filter() \uc870\uac74\uc5d0 \ubd80\ud569\ud558\ub294 \ub370\uc774\ud0c0\ub97c \ucd94\ucd9c\ud569\ub2c8\ub2e4. Optional&lt;Map.Entry&lt;String, String&gt;&gt; entry = map .entrySet() .stream() .filter(e -&gt; e.getKey().equals(&quot;key02&quot;)) .findFirst(); entry.ifPresent(stringStringEntry -&gt; System.out.println(&quot;[key]:&quot; + stringStringEntry.getKey() + &quot;, [value]:&quot; + stringStringEntry.getValue())\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6967\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-6967","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6967"}],"version-history":[{"count":2,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6967\/revisions"}],"predecessor-version":[{"id":6970,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6967\/revisions\/6970"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}