{"id":1590,"date":"2024-09-20T11:25:12","date_gmt":"2024-09-20T02:25:12","guid":{"rendered":"https:\/\/skanto.co.kr\/?p=1590"},"modified":"2024-09-20T15:02:36","modified_gmt":"2024-09-20T06:02:36","slug":"java-stream-api-mastering-collectors","status":"publish","type":"post","link":"https:\/\/skanto.co.kr\/?p=1590","title":{"rendered":"Java Stream API: Mastering Collectors"},"content":{"rendered":"\n<p>Java\uc5d0\uc11c Stream\uc744 \uc774\uc6a9\ud560 \ub54c \uadf8 \uac12\uc774 \ud558\ub098\uc758 \uac12\uc774\ub4e0, Collection\uc774\ub4e0 \ub610\ub294 \ubc30\uc5f4\uc774\ub4e0\uac04\uc5d0 \ucd5c\uc885 \uacb0\uacfc\uac12\uc744 \uc0b0\ucd9c\ud558\uac8c \ub41c\ub2e4. Java\uc5d0\uc11c Stream\uc740 Collector\ub4e4\uc744 \ud1b5\uacfc\ud558\uba74\uc11c \uc5b4\ub5a4 \ud615\ud0dc\uc758 Container\ub85c \ubcc0\ud658\ub41c\ub2e4. Java Stream API\ub294 \ub2e4\uc591 \ud615\ud0dc\uc758 Collector\ub4e4\uc744 \uc81c\uacf5\ud558\uba70 \uc774 \uae00\uc5d0\uc11c \uc774\ub7f0 Collector\ub4e4\uc744 \ud558\ub098\uc529 \uc0b4\ud3b4\ubcf4\uace0\uc790 \ud55c\ub2e4.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*9pYSBOXuQx0fMI6KIMxVMQ.jpeg\" alt=\"\"\/><\/figure>\n<\/div>\n\n\n<p>Stream\uc744 Collection\uc73c\ub85c \ubcc0\ud615\uc2dc\ud0a4\ub294 \uac83\uc740 \uad11\ubc94\uc704\ud55c \ud1a0\ud53d\uc774\ub77c \ud560 \uc218 \uc788\ub2e4. \ub530\ub77c\uc11c \ub2e4\uc591\ud55c \ud234\ub4e4\uc774 \uc874\uc7ac\ud558\uace0 \ub2e4\uc591\ud55c \ubc29\ubc95\uc73c\ub85c \ud65c\uc6a9\ud558\uac70\ub098 \ubb34\uc218\ud55c \uc870\ud569\uc73c\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc73c\ubbc0\ub85c \uc5b8\uc81c, \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ud558\ub294\uc9c0\uc5d0 \ub300\ud574 \ubaa8\ub450 \uc774\ud574\ud558\ub294 \uac83\uc740 \ud604\uc2e4\uc131\uc774 \ub5a8\uc5b4\uc9c4\ub2e4. \ud65c\uc6a9\ubc29\ubc95\uc5d0 \ub300\ud574 \uc880 \ub354 \uc27d\uac8c \uc811\uadfc\ud560 \uc218 \uc788\ub3c4\ub85d \uc5b4\ub5bb\uac8c \uc18c\uac1c\ud560 \uc9c0 \uc2dc\ub098\ub9ac\uc624\ub97c \uc81c\uc2dc\ud558\uace0\uc790 \ud55c\ub2e4.<\/p>\n\n\n\n<p>\uac00\uc7a5 \uc774\ud574\ud558\uae30 \uc26c\uc6b4 \ubc29\ubc95\uc73c\ub85c \ub2e4\uc774\uc5b4\uadf8\ub7a8\uc744 \ud65c\uc6a9\ud558\ub294 \uac83\uc744 \uc0dd\uac01\ud574 \ubcfc \uc218 \uc788\ub2e4. \ub2e4\uc774\uc5b4\uadf8\ub7a8\uc740 \ub2e4\uc591\ud55c Stream \uad6c\uc870\ub97c \uc870\uc9c1\ud654\ud558\ub294\ub370 \ub3c4\uc6c0\uc774 \ub418\uace0 \ud5a5\ud6c4\uc5d0 \ud2b9\uc815 \uc5c5\ubb34\uc5d0 \uc54c\ub9de\uc740 \ud234\uc744 \uc120\uc815\ud558\ub294\ub370\uc5d0 \ub3c4\uc6c0\uc744 \uc904 \uc218 \uc788\ub2e4. \ud558\uc9c0\ub9cc \ub354 \uc88b\uc740 \ubc29\ubc95\uc774 \uc788\ub2e4\uba74 \uadf8\uac83\uc744 \ud65c\uc6a9\ud574\ub3c4 \uc88b\ub2e4.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*4PLtvvlDa0YWmOX-X1nPmg.jpeg\" alt=\"\"\/><\/figure>\n<\/div>\n\n\n<p>Java\uc5d0\uc11c Stream\uc744 Collect\ud560 \uc218 \uc788\ub294 \ubc29\ubc95\uc740 \ub2e4\uc591\ud558\ub2e4. Stream \uc778\ud130\ud398\uc774\uc2a4\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 method\ub97c \uc9c1\uc811 \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\ub3c4 \uc788\uace0 \ud2b9\ud654\ub41c Collector\ub97c \ubc18\ud658\ud574 \uc8fc\ub294 <code>Collectors<\/code>\ud074\ub798\uc2a4\uc758 method\ub97c \ud65c\uc6a9\ud558\ub294 \ubc29\ubc95\ub3c4 \uc788\ub2e4. \uc774\ub4e4 Collector\ub4e4\uc740<code> Collection<\/code>\uc778\ud130\ud398\uc774\uc2a4, <code>Map<\/code> \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\ub294 \uac1d\uccb4\uc5d0 element\ub97c \ucd95\uc801\ud560 \uc218 \uc788\uac70\ub098 \uc2ec\uc9c0\uc5b4 <code>String<\/code> \uac1d\uccb4\uc5d0 \uc9c1\uc811 \ucd95\uc801\ud574 \ub098\uac08 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>Collector\ub4e4\uc740 <code>partitionBy<\/code>\uc640 <code>groupBy<\/code>\uc640 \uac19\uc740 \uc5f0\uc0b0\uc744 \uc774\uc6a9\ud558\uc5ec \ub370\uc774\ud130\ub97c Map \uac1d\uccb4\ub85c collect\ud560 \ub54c \ud2b9\ud788 \uac15\ub825\ud574 \uc9c8 \uc218 \uc788\ub2e4. Downstream collector\ub4e4\uc740 \uc5b4\ub5a4 \ud0c0\uc785\uc758 Collection\uc774\ub4e0\uac04\uc5d0 \uc801\uc6a9\ud560 \uc218\ub294 \uc788\uc9c0\ub9cc <code>Map<\/code>\uac1d\uccb4\ub85c collect\ud558\uc5ec \ub354\uc6b1 \uc815\uc81c\ub41c \uc5f0\uc0b0\uc744 \uc218\ud589\ud560  \ub54c \uac00\uc7a5 \uc720\uc6a9\ud558\ub2e4. \uc790, \uadf8\ub7fc \uc774\ub7f0 collector\ub4e4\uc744 \ud558\ub098\uc529 \uc790\uc138\ud558\uac8c \uc0b4\ud3b4\ubcf4\uc790<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Stream Methods<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><em>toList()<\/em><\/h3>\n\n\n\n<p>Stream\uc744 Collection\uc73c\ub85c \ubcc0\ud658\ud558\ub294 \uac00\uc7a5 \ub2e8\uc21c\ud55c \ubc29\ubc95\uc740 <code>toList<\/code> \uba54\uc18c\ub4dc\ub97c \ud65c\uc6a9\ud558\ub294 \uac83\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>default List&lt;T&gt; toList() {...}<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 Java 16\ubd80\ud130 \uc0ac\uc6a9 \uac00\ub2a5\ud558\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; example1 = Stream.of(1, 2, 3)\n         .toList();\n \/\/ &#91;1, 2, 3]\n \/\/ example1.add(4); \/\/ -- throws UnsupportedOperationException<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\uc758 \ubc18\ud658 \uac12\uc740 unmodifiable list\uc774\ub2e4. \ub530\ub77c\uc11c \uc774 \uac12\uc5d0 \uc0c8\ub85c\uc6b4 element\ub97c \ucd94\uac00\ud558\ub294 \uac83\uacfc \uac19\uc774 \ubcc0\uacbd\uc744 \uac00\ud560 \uacbd\uc6b0 <code>UnsupportedOperationException<\/code>\uc774 \ubc1c\uc0dd\ud55c\ub2e4.<\/p>\n\n\n\n<p><code>IntStream<\/code>, <code>LongStream<\/code>, <code>DoubleStream<\/code>\uacfc \uac19\uc740 Numeric Stream \uc778\ud130\ud398\uc774\uc2a4\ub294 \uc774 method\ub97c \uc81c\uacf5\ud558\uc9c0 \uc54a\ub294\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><em>toArray()<\/em><\/h3>\n\n\n\n<p>toArray\uba54\uc18c\ub4dc\ub97c \uc774\uc6a9\ud558\uba74 element\ub4e4\uc744 Array\ub85c collect\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Object&#91;] toArray();<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc774 \uc0ac\uc6a9\ub41c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Object&#91;] example2 = Stream.of(1, 2, 3)\n        .toArray();\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<p>Generic Array\ub4e4\uc740 \ub7f0\ud0c0\uc784 \uc0c1\ud669\uc5d0\uc11c \uc778\uc2a4\ud134\uc2a4\ud654\uac00 \ub420 \uc218 \uc5c6\uae30 \ub54c\ubb38\uc5d0  \uc774 \uba54\uc18c\ub4dc\ub294 object array(<code>Object[]<\/code>)\ub97c \ubc18\ud658\ud55c\ub2e4. \ub610\ud55c \uc774 \uba54\uc18c\ub4dc\ub294 generation function\uc744 \ud30c\ub77c\ubbf8\ud130\ub85c \ubc1b\uc744 \uc218 \uc788\ub294 Overload\ub41c \ubc84\uc804\ub3c4 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;A&gt; A&#91;] toArray(IntFunction&lt;A&#91;]&gt; generator);<\/code><\/pre>\n\n\n\n<p>\uc774\ub54c Generator function\uc740 \ubc30\uc5f4\uc758 \ud06c\uae30(size) \uadf8\ub9ac\uace0 \uc774\uc640 \ub3d9\uc77c\ud55c size\uc758 Array\ub97c \ubc18\ud658\ud55c\ub2e4\ub294 \uac83\uc744 \uc758\ubbf8\ud558\ub294 integer\ub97c \uc804\ub2ec \ubc1b\ub294\ub2e4. \uc774\ub7f0 \uc77c\ub828\uc758 \uacfc\uc815\ub4e4\uc740 array \uc0dd\uc131\uc790 reference\ub97c \uc774\uc6a9\ud558\uba74 \uac04\uacb0\ud558\uac8c \ud45c\ud604\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer&#91;] example3 = Stream.of(1, 2, 3)\n        .toArray(Integer&#91;]::new);\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<p>\uac01 Numeric stream \uc778\ud130\ud398\uc774\uc2a4\ub294 Stream\uc758 \ud0c0\uc785\uacfc \ub3d9\uc77c\ud55c \ud0c0\uc785\uc758 Array\ub97c \ubc18\ud658\ud558\ub294 <code>toArray<\/code> \uba54\uc18c\ub4dc\ub97c \uc81c\uacf5\ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int&#91;] example4 = IntStream.of(1, 2, 3)\n        .toArray();\n\/\/ &#91;1, 2, 3]\n\nlong&#91;] example5 = LongStream.of(1L, 2L, 3L)\n        .toArray();\n\/\/ &#91;1, 2, 3]\n\ndouble&#91;] example6 = DoubleStream.of(1.1, 2.2, 3.3)\n        .toArray();\n\/\/ &#91;1.1, 2.2, 3.3]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Collect methods<\/h2>\n\n\n\n<p>Stream \uc778\ud130\ud398\uc774\uc2a4\ub294 \ub450 \uac1c\uc758 overload\ub41c <code>collect<\/code> \uba54\uc18c\ub4dc\ub97c \uc81c\uacf5\ud55c\ub2e4. \uadf8 \uc911 \uccab \ubc88\uc9f8 \uba54\uc18c\ub4dc\ub294 \uc544\ub798\uc758 \ud615\ud0dc\ub97c \uac16\ub294\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;R, A&gt; R collect(Collector&lt;? super T, A, R&gt; collector);<\/code><\/pre>\n\n\n\n<p>\uadf8\ub9ac\uace0 \ub450 \ubc88\uca30 \uba54\uc18c\ub4dc\ub294 \uc544\ub798\uc640 \uac19\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;R&gt; R collect(Supplier&lt;R&gt; supplier,\n              BiConsumer&lt;R, ? super T&gt; accumulator,\n              BiConsumer&lt;R, R&gt; combiner);<\/code><\/pre>\n\n\n\n<p>\uccab \ubc88\uc9f8 \uba54\uc18c\ub4dc\ub294 <code>Collector<\/code>\ub97c \ud30c\ub77c\ubbf8\ud130\ub85c \ubc1b\ub294 \ubc18\uba74 \ub450 \ubc88\uc9f8 \uba54\uc18c\ub4dc\ub294 <code>Supplier<\/code>\uc640 \ub450 \uac1c\uc758 <code>BiConsumer<\/code> \uac1d\uccb4\ub97c \ubc1b\ub294\ub2e4. \uc774 \uae00\uc758 \uccab \ubc88\uc9f8 \ud30c\ud2b8\ub294 \uccab \ubc88\uc9f8 \uba54\uc18c\ub4dc\uc758 \uc0ac\uc6a9\ubc95\uc5d0 \ub300\ud574 \uc124\uba85\ud558\uace0 \ub450 \ubc88\uc9f8 \ubc29\ubc95\uc740 \ub098\uc911\uc5d0 \uc124\uba85\ud558\uace0\uc790 \ud55c\ub2e4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Collectors<\/h2>\n\n\n\n<p>Java Stream API\uc758 \uc778\ud130\ud398\uc774\uc2a4\uc778 \uccab \ubc88\uc9f8 collection \uba54\uc18c\ub4dc\ub294 <code>Collector<\/code>\ub97c \ud30c\ub77c\ubbf8\ud130\ub85c \ubc1b\ub294\ub2e4. API\ub294 \uc27d\uac8c \uc801\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d <code>Collectors<\/code> \ud074\ub798\uc2a4\ub97c \uc81c\uacf5\ud558\uba70 \uc774 \ud074\ub798\uc2a4\uac00 \uc81c\uacf5\ud558\ub294 \ub2e4\uc591\ud55c method\ub4e4\uc740 Collector\ub97c \ubc18\ud658\ud55c\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.toCollection()<\/em><\/h3>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 supplier \ud0c0\uc785\uc758 \ud30c\ub77c\ubbf8\ud130\ub97c \uac00\uc9c4\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T, C extends Collection&lt;T&gt;&gt;\nCollector&lt;T, ?, C&gt; toCollection(Supplier&lt;C&gt; collectionFactory) {...}<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 <code>Collection<\/code> \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\ub294 \uc5b4\ub5a4 \ud615\ud0dc\uc758 collection\uc774\ub4e0 Stream\uc744 Collection\uc73c\ub85c collect\ud560 \ub54c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ArrayList&lt;Integer&gt; example7 = Stream.of(1, 2, 3)\n        .collect(Collectors.toCollection(ArrayList::new));\n\/\/ &#91;1, 2, 3]\n\nSet&lt;Integer&gt; example8 = Stream.of(1, 2, 3)\n        .collect(Collectors.toCollection(HashSet::new));\n\/\/ &#91;1, 2, 3]\n\nArrayList&lt;Integer&gt; example9List = new ArrayList&lt;&gt;();\nexample9List.add(0);\nArrayList&lt;Integer&gt; example9 = Stream.of(1, 2, 3)\n        .collect(Collectors.toCollection(() -&gt; example9List));\n\/\/ &#91;0, 1, 2, 3]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.toList()<\/em><\/h3>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 \uc774\ub984\uc5d0\uc11c \ubcf4\ub4ef Stream\uc758 element\ub4e4\uc744 List\ub85c \ucde8\ud569\ud574 \uc8fc\ub294 \uc9c1\uad00\uc801\uc778 collector\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; example10 = Stream.of(1, 2, 3)\n        .collect(Collectors.toList());\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.toUnmodifiableList()<\/em><\/h3>\n\n\n\n<p>unmodifiable \ub9ac\uc2a4\ud2b8\ub97c \ubc18\ud658\ud558\uae30 \ub54c\ubb38\uc5d0 Stream\uc758 <code>toList()<\/code> \uba54\uc18c\ub4dc\ub97c \uc9c1\uc811 \ud638\ucd9c\ud558\ub294 \uac83\uacfc \uc720\uc0ac\ud558\uac8c \ub3d9\uc791\ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; example11 = Stream.of(1, 2, 3)\n        .collect(Collectors.toUnmodifiableList());\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.toSet() \uacfc Collectors.toUnmodifiableSet()<\/em><\/h3>\n\n\n\n<p>\uc774\ub4e4 \uba54\uc18c\ub4dc\ub294 \uc55e\uc5d0\uc11c \uc124\uba85\ud55c \ub450  \uba54\uc18c\ub4dc\uc640 \uc720\uc0ac\ud558\uac8c \ub3d9\uc791\ud558\uc9c0\ub9cc \ubc18\ud658\ub418\ub294 \uacb0\uacfc\ub294 <code>List<\/code>\uac00 \uc544\ub2c8\ub77c <code>Set<\/code>\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Set&lt;Integer&gt; example12 = Stream.of(1, 2, 3)\n        .collect(Collectors.toSet());\n\/\/ &#91;1, 2, 3]\n\nSet&lt;Integer&gt; example13 = Stream.of(1, 2, 3)\n        .collect(Collectors.toUnmodifiableSet());\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.collectingAndThen()<\/em><\/h3>\n\n\n\n<p><code>collectingAndThen()<\/code>\uc740 Java Stream API\uc5d0\uc11c \ud2b9\ubcc4\ud55c collector\ub85c two-step collection\uacfc\uc815\uc744 \uac70\uce5c\ub2e4. \uccab \ubc88\uca30\ub294 <code>toList()<\/code> \ub610\ub294 <code>toSet()<\/code>\uacfc \uac19\uc774 \ub2e4\ub978 collector\ub97c \uc774\uc6a9\ud558\uc5ec element\ub4e4\uc744 collect\ud558\uace0 \uadf8 \ub2e4\uc74c\uc73c\ub85c \uacb0\uacfc \uac12\uc5d0 \ub300\ud574 finishing transformation function\uc744 \uc801\uc6a9\ud55c\ub2e4. \uc774\ub294 \ub370\uc774\ud130\ub97c collect\ud55c \ud6c4 \ubc14\ub85c \ub2e4\uc74c\uc73c\ub85c unmodifiable collection\uc73c\ub85c \ub9cc\ub4e0\ub2e4\uac70\ub098 \ub370\uc774\ud130\ub97c custom \uac1d\uccb4\ub85c \ubcc0\ud658, \ub610\ub294 \ucd94\uac00\uc801\uc778 \uc5f0\uc0b0 \uacfc\uc815\uacfc \uac19\uc740 \ud6c4\uc18d\ucc98\ub9ac\ub97c \ud558\uace0\uc790 \ud560 \uacbd\uc6b0\uc5d0 \uc720\uc6a9\ud558\uac8c \ud65c\uc6a9\ud560 \uc218 \uc788\ub2e4. \uc774\ub294 stream collection \ub85c\uc9c1\uc5d0\uc11c \ud6c4\ucc98\ub9ac(post-processing) \ub2e8\uacc4\ub97c \ucd94\uac00\ud574 \uc8fc\ub294 \uac15\ub825\ud55c \ubc29\ubc95\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer> example14 = Stream.of(1, 2, 3)\n        .collect(Collectors.collectingAndThen(\n                Collectors.toList(), Collections::unmodifiableList));\n\/\/ &#91;1, 2, 3]\n\nclass CustomClass {\n    private List&lt;Integer> streamOutput;\n    CustomClass(List&lt;Integer> streamOutput) {\n        this.streamOutput = new ArrayList&lt;>(streamOutput);\n    }\n    @Override\n    public String toString() {\n        return \"CustomClass{\" +\n                \"streamOutput=\" + streamOutput +\n                '}';\n    }\n}\n\nCustomClass example15 = Stream.of(1, 2, 3)\n        .collect(Collectors.collectingAndThen(\n                Collectors.toList(), CustomClass::new));\n\/\/ CustomClass{streamOutput=&#91;1, 2, 3]}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Collectors.teeing()<\/em><\/h3>\n\n\n\n<p>Java 12\uc5d0\uc11c \uc18c\uac1c\ub41c collector\ub294 \ud558\ub098\uc758 Stream\uc744 \ub450 \ud30c\ud2b8\ub85c \ubd84\ub9ac\ud558\uace0 \uac01 \ud30c\ud2b8\ub294 \uc11c\ub85c \ub2e4\ub978 \ub3c5\ub9bd\uc801\uc778 collector\ub97c \ud65c\uc6a9\ud558\uc5ec \uac01\uc790 \ucc98\ub9ac\ud55c \ub2e4\uc74c \uac01\uac01\uc758 \uacb0\uacfc\ub294 merging function\uc744 \uc774\uc6a9\ud558\uc5ec \ud1b5\ud569\uc2dc\ud0a4\ub3c4\ub85d \ud55c\ub2e4. \uc774\ub294 \ud55c \ubc88\uc5d0 Stream\uc758 \ucd1d\ud569\uacfc \ud3c9\uade0\uac12\uc744 \uacc4\uc0b0\ud558\ub294 \uac83\uacfc \uac19\uc774 \ubcd1\ub82c \ucc98\ub9ac \ubc29\ubc95\uc73c\ub85c reduction\uc744 \uc218\ud589\ud558\uace0\uc790 \ud560 \uacbd\uc6b0 \uc720\uc6a9\ud558\ub2e4. \uc774\ub807\uac8c \ud558\uba74 \uc5ec\ub7ec \uacfc\uc815\uc758 Collection \ucc98\ub9ac\ub97c \ud55c \ubc88\uc758 Stream \uc5f0\uc0b0\uc73c\ub85c \ud1b5\ud569\uc2dc\ucf1c \uc90c\uc73c\ub85c \uc131\ub2a5\uc744 \ud5a5\uc0c1\uc2dc\ud0ac \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String example16 = Stream.of(1, 2, 3).collect(\n        Collectors.teeing(\n                Collectors.summingInt(Integer::intValue), \/\/ First collector: sums all elements\n                Collectors.averagingInt(Integer::intValue), \/\/ Second collector: calculates the average\n                (sum, average) -> \n                        String.format(\"Sum: %d, Avg: %.2f\", sum, average) \/\/ Merge the results\n        )\n);\n\/\/ Sum: 6, Avg: 2,00<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Joining collectors<\/h2>\n\n\n\n<p>\ud504\ub85c\uadf8\ub798\ubc0d\ud560 \ub54c String\uc744 \uc774\uc6a9\ud574\uc57c\ud560 \ub2e4\uc591\ud55c \uc2dc\ub098\ub9ac\uc624\uac00  \uc788\ub2e4. Stream API\ub294 CharSequence \ud0c0\uc785\uc758 \uc785\ub825 element\ub97c \ud558\ub098\uc758 immutable String\uc73c\ub85c concatenation\ud560 \uc218 \uc788\ub3c4\ub85d \ud2b9\ubcc4\ud788 \uace0\uc548\ub41c Collector\ub97c \uc81c\uacf5\ud55c\ub2e4. \uc774\ub7f0 Collector\ub4e4 \uc911 \uccab \ubc88\uc9f8\ub294 \uc5b4\ub5a0\ud55c \ud30c\ub77c\ubbf8\ud130\ub3c4 \ubc1b\uc9c0 \uc54a\ub294\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Collector&lt;CharSequence, ?, String> joining() {...}<\/code><\/pre>\n\n\n\n<p>\uc774 Collector\ub294 \uc5ec\ub7ec \ubb38\uc790\uc5f4\ub4e4\uc744 \ud558\ub098\uc758 \ubb38\uc790\uc5f4\ub85c \uc5f0\uacb0\uc2dc\ud0a4\ub294 \uc5ed\ud560\uc744 \ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String example17 = Stream.of(\"String1\", \"String2\", \"String3\")\n        .collect(Collectors.joining());\n\/\/ String1String2String3<\/code><\/pre>\n\n\n\n<p>\ub610 \ub2e4\ub978 Collector\ub294 CharSequence\ub97c \ubcc0\uc218\ub85c \ubc1b\uc73c\uba70 \uc774 \ubcc0\uc218\ub294 \ubb38\uc790\uc5f4\uc744 \ud569\uce60 \ub54c delimiter\ub85c \ud65c\uc6a9\ub41c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Collector&lt;CharSequence, ?, String> joining(CharSequence delimiter) {...}<\/code><\/pre>\n\n\n\n<p>\uc544\ub798\uc640 \uac19\uc774 \ud65c\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String example18 = Stream.of(\"String1\", \"String2\", \"String3\")\n        .collect(Collectors.joining(\"-delimiter-\"));\n\/\/ String1-delimiter-String2-delimiter-String3<\/code><\/pre>\n\n\n\n<p>\ub9c8\uc9c0\ub9c9\uc73c\ub85c \uc18c\uac1c\ud560 Collector\ub294 \uc138 \uac1c\uc758 CharSequence \ud30c\ub77c\ubbf8\ud130\ub97c \ubc1b\ub294\ub2e4. \uac01\uac01 delimiter, prefix, suffix\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Collector&lt;CharSequence, ?, String> joining(CharSequence delimiter,\n                                                         CharSequence prefix,\n                                                         CharSequence suffix) {...}<\/code><\/pre>\n\n\n\n<p>\uc55e\uc560\uc11c \uc124\uba85\ud55c Collector\uc640 \uc720\uc0ac\ud558\uac8c \uccab \ubc88\uc9f8 \ud30c\ub77c\ubbf8\ud130\ub294 delimiter\ub85c \uc0ac\uc6a9\ub418\uace0 \ub450 \ubc88\uc9f8\uc640 \uc138 \ubc88\uc9f8 \ud30c\ub77c\ubbf8\ud130\ub294 \uac01\uac01 prefix\uc640 suffix\ub85c \ud65c\uc6a9\ub41c\ub2e4. prefix\ub294 \ud1b5\ud569\ub41c \ubb38\uc790\uc5f4\uc758 \uc2dc\uc791 \ubd80\ubd84\uc5d0 \ucd94\uac00\ub418\uace0 suffix\ub294 \ub05d\ubd80\ubd84\uc5d0 \ucd94\uac00\ub41c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String example19 = Stream.of(\"String1\", \"String2\", \"String3\")\n        .collect(Collectors.joining(\"-delimiter-\", \"prefix\", \"suffix\"));\n\/\/ prefixString1-delimiter-String2-delimiter-String3suffix<\/code><\/pre>\n\n\n\n<p>\uc774\ub4e4 Collector\uc5d0 \uc0ac\uc6a9\ub418\ub294 \ud30c\ub77c\ubbf8\ud130\uc5d0 <code>null<\/code>\uc774 \uc804\ub2ec\ub420 \uacbd\uc6b0 <code>NullPointerException<\/code>\uc774 \ubc1c\uc0dd\ud558\ubbc0\ub85c \uc8fc\uc758\ub97c \uae30\uc6b8\uc5ec\uc57c \ud55c\ub2e4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Collectors to map<\/h2>\n\n\n\n<p>Element\ub97c \ud558\ub098\uc758 Map\uc73c\ub85c \ucde8\ud569\ud558\ub294 Collector\ub4e4\uc740 \uc77c\ubc18\uc801\uc73c\ub85c \ud45c\uc900 Collection\uc73c\ub85c collect\ud558\ub294 Collector\ub4e4 \ubcf4\ub2e4 \ub354 \ubcf5\uc7a1\ud558\ub2e4. <code>Collectors<\/code> \ud074\ub798\uc2a4\ub294 map collector\ub97c \uc0dd\uc131\ud558\ub294 3\uac1c\uc758 overload\ub41c \uba54\uc18c\ub4dc\ub97c \uc81c\uacf5\ud55c\ub2e4. \uccab \ubc88\uc9f8 \uba54\uc18c\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc740 \ud615\ud0dc\ub97c \uac00\uc9c4\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T, K, U>\nCollector&lt;T, ?, Map&lt;K,U>> toMap(Function&lt;? super T, ? extends K> keyMapper,\n                                Function&lt;? super T, ? extends U> valueMapper) {...}<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 2\uac1c\uc758 <code>Function<\/code> \ud30c\ub77c\ubbf8\ud130\ub97c \ubc1b\uc73c\uba70 \uccab \ubc88\uc9f8 \ud30c\ub77c\ubbf8\ud130\ub294 key\ub97c \ub9e4\ud551\ud558\uba70 \ub450 \ubc88\uc9f8 \ud30c\ub77c\ubbf8\ud130\ub294 value\ub97c \ub9e4\ud551\uc2dc\ud0a8\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Integer, Integer> example20 = Stream.of(1, 2, 3)\n        .collect(Collectors.toMap(k -> k, v -> v * 10));\n\/\/ .collect(Collectors.toMap(Function.identity(), v -> v * 10));\n\/\/ {1=10, 2=20, 3=30}<\/code><\/pre>\n\n\n\n<p>\uc704 \uc0d8\ud50c\uc5d0\uc11c Stream\uc758 \uac01 element\ub4e4\uc740 key\ub85c \uc0ac\uc6a9\ub418\uc5c8\uc73c\uba70 \uc774\uc5d0 \uc0c1\uc751\ud558\ub294 value\ub294 \ud574\ub2f9 element\uc5d0 10\uc744 \uacf1\ud55c \uac12\uc774 \ub41c\ub2e4. key\ub97c \ub9e4\ud551\ud558\uae30 \uc704\ud574 <code>Function.identity()<\/code> \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9\ud560 \uc218\ub3c4 \uc788\ub2e4. \uc774 \uba54\uc18c\ub4dc\ub294 \ub0b4\ubd80\uc801\uc73c\ub85c \ub3d9\uc77c\ud55c \uc5f0\uc0b0\uc744 \uc218\ud589\ud55c\ub2e4.<\/p>\n\n\n\n<p>\uccab \ubc88\uc9f8 <code>toMap<\/code> \uba54\uc18c\ub4dc\ub97c \uad00\ucc30\ud574 \ubcf4\uba74 Stream\uc5d0 \uc911\ubcf5\ub41c element\uac00 \uc788\uc744 \uacbd\uc6b0 \uc5b4\ub5bb\uac8c \ucc98\ub9ac\ub420 \uc9c0 \uad81\uae08\ud560 \uac83\uc774\ub2e4.  \uc774\ub7f0 \uacbd\uc6b0\uac00 \ubc1c\uc0dd\ud558\uba74 <code>IllegalStateException<\/code>\uc744 \ubc1c\uc0dd\uc2dc\ucf1c key\uac00 \uc911\ubcf5\ub418\uc5c8\uc74c\uc744 \uc54c\ub824\uc900\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Integer, Integer> example21 = Stream.of(1, 1, 3)\n        .collect(Collectors.toMap(k -> k, v -> v * 10));\n\/\/ IllegalStateException: Duplicate key 1<\/code><\/pre>\n\n\n\n<p>\uc774 \ubb38\uc81c\ub97c \ud574\uacb0\ud558\uae30 \uc704\ud574 <code>toMap<\/code> \uba54\uc18c\ub4dc\uc758 \uc774\ud6c4 \ubc84\uc804\uc740 <code>BinaryOperator<\/code> \ud0c0\uc785\uc758 \ud30c\ub77c\ubbf8\ud130\ub97c \ucd94\uac00\ud558\uace0 \uc788\ub2e4. \uc774\ub807\uac8c \ud558\uba74 \ud1b5\ud569 \ubc29\ubc95\uc744 \uc9c0\uc815\ud558\uac8c \ud568\uc73c\ub85c\uc368 \uc911\ubcf5\ub41c \ud0a4\ub97c \ucc98\ub9ac\ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T, K, U>\nCollector&lt;T, ?, Map&lt;K,U>> toMap(Function&lt;? super T, ? extends K> keyMapper,\n                                Function&lt;? super T, ? extends U> valueMapper,\n                                BinaryOperator&lt;U> mergeFunction) {...}<\/code><\/pre>\n\n\n\n<p>\uc608\ub97c \ub4e4\uba74 \uc544\ub798\uc758 \ucf54\ub4dc\uc5d0\uc11c \ucc98\ub7fc \uc911\ubcf5\ub41c \ud0a4\ub4e4\uc758 \uac12\ub4e4\uc744 \ud569\uc0b0\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Integer, Integer> example22 = Stream.of(1, 1, 3)\n        .collect(Collectors.toMap(k -> k,\n                v -> v * 10,\n                (v1, v2) -> v1 + v2));\n\/\/ {1=20, 3=30} {1=(1*10) + (1*10), 3=3*10}<\/code><\/pre>\n\n\n\n<p>\ub9c8\uc9c0\ub9c9 method\ub294 \ucd94\uac00\uc801\uc778 <code>Supplier<\/code> \ud30c\ub77c\ubbf8\ud130\ub97c \ud3ec\ud568\ud55c\ub2e4. \uc774\ub97c \ud1b5\ud574 collect\ud558\uace0\uc790 \uc815\ud655\ud55c map \uad6c\ud604\ubc29\ubc95\uc744 \uc9c0\uc815\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T, K, U, M extends Map&lt;K, U>>\nCollector&lt;T, ?, M> toMap(Function&lt;? super T, ? extends K> keyMapper,\n                         Function&lt;? super T, ? extends U> valueMapper,\n                         BinaryOperator&lt;U> mergeFunction,\n                         Supplier&lt;M> mapFactory) {...}<\/code><\/pre>\n\n\n\n<p>\uc608\ub97c \ub4e4\uc5b4, LinkedHashMap \uc73c\ub85c collect\ud558\uace0\uc790 \ud55c\ub2e4\uba74 \uc544\ub798\uc640 \uac19\uc774 \uad6c\ud604\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LinkedHashMap&lt;Integer, Integer> example23 = Stream.of(1, 1, 3)\n        .collect(Collectors.toMap(k -> k,\n                v -> v * 10,\n                (v1, v2) -> v1 + v2,\n                LinkedHashMap::new));\n\/\/ {1=20, 3=30} {1=(1*10) + (1*10), 3=3*10}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Partitioning by collectors<\/h2>\n\n\n\n<p>Java Stream\uc5d0\uc11c <code>Collectors.partitioningBy<\/code>\ub294 predicate\uc5d0 \uae30\ubc18\ud558\uc5ec Stream\uc744 \ub450 \uac1c\uc758 \ud30c\ud2f0\uc158\uc73c\ub85c \ubd84\ub9ac\uc2dc\ud0a8\ub2e4\ub294 \uc810\uc5d0\uc11c \uc720\uc6a9\ud55c collector\ub4e4\uc911 \ud558\ub098\uc774\ub2e4. \uc774 \uba54\uc18c\ub4dc\ub294 <code>Map&lt;Boolean, List&lt;T>><\/code>\ub97c \ubc18\ud658\ud558\ub294\ub370 \uc774\ub584 <code>true<\/code>\uac12\uc758 key\ub294 predicate\uacfc \ub9e4\uce6d\ud558\ub294 element\ub4e4\uc744 \uac00\uc9c0\uba70 <code>false<\/code>\uac12\uc758 \ud0a4\ub294 \uadf8\ub807\uc9c0 \ubabb\ud55c element\ub4e4\uc744 \uac16\ub294\ub2e4. \uc774 Collector\ub294 \uc870\uac74\uc5d0 \ub530\ub77c \ub450 \uac1c\uc758 \ubd84\ub9ac\ub41c \uadf8\ub8f9\uc73c\ub85c \uce74\ud14c\uace0\ub9ac\ub97c \ub098\ub204\uace0\uc790 \ud560 \uacbd\uc6b0 \uc720\uc6a9\ud558\uac8c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 2\uac1c\uc758 overload\ub41c \ubc84\uc804\uc744 \uac00\uc9c4\ub2e4. \uccab \ubc88\uc9f8\ub294 predicate \ud0c0\uc785\uc758 \ud30c\ub77c\ubbf8\ud130 \ud55c \uac1c\ub97c \uac00\uc9c4\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T>\nCollector&lt;T, ?, Map&lt;Boolean, List&lt;T>>> partitioningBy(Predicate&lt;? super T> predicate) {...}<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 \uc608\ub97c \ub4e4\uc5b4 \uc22b\uc790\uac00 \uc9dd\uc218\uc778\uc9c0 \ud640\uc218\uc778\uc9c0\uc5d0 \ub530\ub77c Stream\uc744 \ubd84\ud560\ud558\uace0\uc790 \ud560 \uacbd\uc6b0 \uc544\ub798\uc640 \uac19\uc774 \ud65c\uc6a9\ub420 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Boolean, List&lt;Integer>> example24 = Stream.of(1, 2, 3)\n        .collect(Collectors.partitioningBy(el -> el % 2 == 0));\n\/\/ {false=&#91;1, 3], true=&#91;2]}<\/code><\/pre>\n\n\n\n<p>\uc774 \uc0d8\ud50c\uc5d0\uc11c stream\uc740 \uc9dd\uc218 List\uc640(true \ud0a4) \ud640\uc218 List(false \ud0a4) \ub450 \uadf8\ub8f9\uc73c\ub85c \ubd84\ub9ac\ub418\uc5c8\ub2e4.<\/p>\n\n\n\n<p>\ub450 \ubc88\uc9f8 \ubc84\uc804\uc740 Collector\ud0c0\uc785\uc758 \ucd94\uac00 \ud30c\ub77c\ubbf8\ud130\ub97c \ubc1b\uc73c\uba70 \uc774 Collector\ub294 \uac01 \ud30c\ud2f0\uc158\uc758 element\ub4e4\ub97c \ucc98\ub9ac\ud55c\ub2e4. \uc774 Collector\ub294 \uac01 \ud30c\ud2f0\uc158 \ub0b4\uc758 \ubaa8\ub4e0 Element\uc5d0 \ub300\ud574 \ucd94\uac00\uc801\uc778 \ucde8\ud569(aggregation)\uc640 \ubcc0\ud658(transformation)\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub2e4. \uc608\ub97c \ub4e4\uc5b4 element\ub4e4\uc744 list, set \ud615\ud0dc\ub85c collect\ud558\uac70\ub098 \uc2ec\uc9c0\uc5b4 \uc694\uc57d(summary)\uc5f0\uc0b0\uc744 \uc218\ud589\ud558\uace0\uc790 \ud560 \uacbd\uc6b0\uc5d0\ub3c4 \uc774 \uba54\uc18c\ub4dc\ub97c \uc801\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T, D, A>\nCollector&lt;T, ?, Map&lt;Boolean, D>> partitioningBy(Predicate&lt;? super T> predicate,\n                                                Collector&lt;? super T, A, D> downstream) {...}<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 element\ub4e4\uc744 \ub450 \uadf8\ub8f9\uc73c\ub85c \ubd84\ub9ac\ud558\ub294 \uac83\ubfd0\ub9cc \uc544\ub2c8\ub77c \uac01 \uadf8\ub8f9\uc744 \ub300\uc0c1\uc73c\ub85c \ucd94\uac00\uc801\uc778 downstream collection \ub610\ub294 \ubcc0\ud658(transformation) \uc5f0\uc0b0\uc744 \uc801\uc6a9\ud568\uc73c\ub85c\uc368 \ubcf4\ub2e4 \ub354 \ubcf5\uc7a1\ud55c \ud30c\ud2f0\uc158\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub3c4\ub85d \ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Boolean, Set&lt;Integer>> example25 = Stream.of(1, 2, 3, 4, 5, 6)\n        .collect(Collectors.partitioningBy(\n                el -> el % 2 == 0,  \/\/ Predicate to partition by even or odd\n                Collectors.toSet()   \/\/ Downstream collector to collect into a set\n        ));\n\/\/ {false=&#91;1, 3, 5], true=&#91;2, 4, 6]}<\/code><\/pre>\n\n\n\n<p>\uc544\ub798 \uc0d8\ud50c\uc740 \uac01 \ud30c\ud2f0\uc158\uc5d0\uc11c \ucd5c\ub300\uac12\uc758 Element\ub97c \ucc3e\uc544\ub0b4\ub294 \ubc29\ubc95\uc744 \ubcf4\uc5ec\uc900\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Boolean, Optional&lt;Integer>> example26 = Stream.of(1, 2, 3, 4, 5, 6)\n        .collect(Collectors.partitioningBy(\n                el -> el % 2 == 0,  \n                Collectors.maxBy(Integer::compare)\n        ));\n\/\/ {false=Optional&#91;5], true=Optional&#91;6]}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Grouping By Collectors and Downstream Collectors<\/h2>\n\n\n\n<p>Downstream Collector\ub294 grouped \ub610\ub294 partitioned \ub370\uc774\ud130\ub97c \ub300\uc0c1\uc73c\ub85c \ucd94\uac00\uc801\uc778 \uc5f0\uc0b0\uc744 \uc218\ud589\ud558\uae30 \uc704\ud574 <code>Collectors.groupingBy() <\/code>\ub610\ub294 <code>Collectors.partitioningBy()<\/code> \uc640 \uac19\uc774 \uc0ac\uc6a9\ub41c\ub2e4. \uc774\ub4e4 Collector\ub4e4\uc740 \uadf8\ub8f9\ud551\ub41c \ub370\uc774\ud130\uac00 \ucde8\ud569(aggregate), \ubcc0\ud615(transform), reduce\ub418\ub294 \uacfc\uc815\uc744 Customize\ud560 \uc218 \uc788\ub3c4\ub85d \ud55c\ub2e4.<\/p>\n\n\n\n<p>\uc55e\uc5d0\uc11c \uc5b8\uae09\ud55c \ud29c\ud1a0\ub9ac\uc5bc\uc740 <code>Collectors.filtering()<\/code>, <code>Collectors.mapping()<\/code>, <code>Collectors.flatMapping()<\/code>, <code>Collectors.couting()<\/code>, <code>Collectors.maxBy()<\/code>, <code>Collectors.minBy()<\/code>\uc640 \uac19\uc740 \uac83\ub4e4\uc744 \ud3ec\ud568\ud574\uc11c \uc774\ub7f0 Collector\ub4e4\uc744  \ud65c\uc6a9\ud55c \ub2e4\uc591\ud55c \uc0d8\ud50c\ub4e4\uc744 \uc81c\uacf5\ud55c\ub2e4. \uc774\ub7f0 \ud615\ud0dc\uc758 \uc0d8\ud50c\ub4e4\uc744 \uacc4\uc18d \ubc18\ubcf5\ud558\ub294 \uac83\ubcf4\ub2e4 \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc744 \uc880 \ub354 \uc2ec\uce35\uc801\uc73c\ub85c \ud30c\ud5e4\uccd0\ubcf4\ub294 \uac83\uc744 \uac15\ub825\ud558\uac8c \uad8c\ud574\ubcf8\ub2e4.<\/p>\n\n\n\n<p>\uc55e\uc11c \uc5b8\uae09\ud55c \uac83\ucc98\ub7fc \uc774\uc81c\ubd80\ud130 \ub450 \ubc88\uc9f8 <code>collect<\/code> \uba54\uc18c\ub4dc\uc5d0 \ub300\ud574 \ub2e4\uc2dc \uc0b4\ud3b4\ubcf4\ub3c4\ub85d \ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;R> R collect(Supplier&lt;R> supplier,\n              BiConsumer&lt;R, ? super T> accumulator,\n              BiConsumer&lt;R, R> combiner);<\/code><\/pre>\n\n\n\n<p>\uc774 \uba54\uc18c\ub4dc\ub294 Java Stream\uc5d0\uc11c element\ub4e4\uc744 List, Set, Map\uacfc \uac19\uc774 mutable container\ub85c \ub204\uc801(accumulate)\ud558\ub3c4\ub85d\ud558\ub294 mutable reduction \uc5f0\uc0b0\uc774\ub2e4.<\/p>\n\n\n\n<p>\ub2e4\uc74c\uc758 \uc0d8\ud50c\uc740 Stream&lt;Integer>\uc744 List&lt;Integer>\ub85c collect\ud558\uae30 \uc704\ud574 \uc774 \uba54\uc18c\ub4dc\ub97c \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ud558\ub294\uc9c0\ub97c \ubcf4\uc5ec\uc900\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer> example27 = Stream.of(1, 2, 3).collect(\n        \/\/ Supplier: Provides a new ArrayList\n        ArrayList::new,\n        \/\/ Accumulator: Adds each element to the ArrayList\n        List::add,\n        \/\/ Combiner: Merges two lists (useful for parallel processing)\n        List::addAll\n);\n\/\/ &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<p>\ub2e4\uc74c\uc740 \uc774 \uba54\uc18c\ub4dc\ub97c \ud65c\uc6a9\ud558\ub294 \ub610 \ub2e4\ub978 \uc0d8\ud50c\uc774\ub2e4. \uc774\ubc88\uc5d0\ub294 <code>List<\/code>\uac00 \uc544\ub2c8\ub77c <code>Map<\/code>\uc73c\ub85c Element\ub4e4\uc744 Collect\ud558\ub294 \ubc29\ubc95\uc744 \ubcf4\uc5ec\uc900\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;Integer, Integer> example28 = Stream.of(1, 2, 3).collect(\n        \/\/ Supplier: Creates a new HashMap\n        HashMap::new,\n        \/\/ Accumulator: Adds each number and its square to the Map\n        (map, number) -> map.put(number, number * number),\n        \/\/ Combiner: Merges two maps (useful for parallel processing)\n        Map::putAll\n);\n\/\/ {1=1, 2=4, 3=9}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ub9c8\uce58\uba70&#8230;<\/h2>\n\n\n\n<p>Stream API\ub294 Java \uac1c\ubc1c\uc790\ub4e4\uc774 \uc77c\ubc18\uc801\uc73c\ub85c \uc0ac\uc6a9\ud558\ub294 \uac83\ubcf4\ub2e4 \ub354 \ub9ce\uc740 \uae30\ub2a5\ub4e4\uc744 \uc81c\uacf5\ud568\uc73c\ub85c\uc368 data stream\uc744 collect\ud558\uace0 manipulation\ud558\ub294\ub370 \ud544\uc694\ud55c \uad11\ubc94\uc704\ud558\uace0 \uc2ec\uce35\uc801\uc778 \ud234\uc14b\uc744 \uc81c\uc2dc\ud55c\ub2e4. \ud558\uc9c0\ub9cc \ud544\uc694\ud55c \uacf3\uc774 \uc788\uc5b4\uc57c \uc774\ub7f0 \uac15\ub825\ud55c \ud234\uc774 \uc720\uc6a9\ud558\ub2e4\ub294 \uac83\uc744 \uc78a\uc9c0 \uc54a\uc558\uc73c\uba74 \ud55c\ub2e4. \uc774 \uae00\uc740 \uc774\ub7f0 Stream API\uac00 \uac00\uc9c4 \ub2a5\ub825\ub4e4\uc744 \ubcf4\uc5ec\uc90c\uc73c\ub85c\uc368 \uc5ec\ub7ec\ubd84\ub4e4\uc774 \ud544\uc694\ub85c \ud558\ub294 \uacf3\uc5d0 \uc801\uc808\ud788 \uc798 \uc0ac\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d \ud558\ub294 \uac83\uc744 \ubaa9\ud45c\ub85c \ud55c\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\uc5d0\uc11c Stream\uc744 \uc774\uc6a9\ud560 \ub54c \uadf8 \uac12\uc774 \ud558\ub098\uc758 \uac12\uc774\ub4e0, Collection\uc774\ub4e0 \ub610\ub294 \ubc30\uc5f4\uc774\ub4e0\uac04\uc5d0 \ucd5c\uc885 \uacb0\uacfc\uac12\uc744 \uc0b0\ucd9c\ud558\uac8c \ub41c\ub2e4. Java\uc5d0\uc11c Stream\uc740 Collector\ub4e4\uc744 \ud1b5\uacfc\ud558\uba74\uc11c \uc5b4\ub5a4 \ud615\ud0dc\uc758 Container\ub85c \ubcc0\ud658\ub41c\ub2e4. Java Stream API\ub294 \ub2e4\uc591 \ud615\ud0dc\uc758 Collector\ub4e4\uc744 \uc81c\uacf5\ud558\uba70 \uc774 \uae00\uc5d0\uc11c \uc774\ub7f0 Collector\ub4e4\uc744 \ud558\ub098\uc529 \uc0b4\ud3b4\ubcf4\uace0\uc790 \ud55c\ub2e4. Stream\uc744 Collection\uc73c\ub85c \ubcc0\ud615\uc2dc\ud0a4\ub294 \uac83\uc740 \uad11\ubc94\uc704\ud55c \ud1a0\ud53d\uc774\ub77c \ud560 \uc218 \uc788\ub2e4. \ub530\ub77c\uc11c \ub2e4\uc591\ud55c \ud234\ub4e4\uc774 \uc874\uc7ac\ud558\uace0 \ub2e4\uc591\ud55c \ubc29\ubc95\uc73c\ub85c \ud65c\uc6a9\ud558\uac70\ub098 \ubb34\uc218\ud55c \uc870\ud569\uc73c\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc73c\ubbc0\ub85c \uc5b8\uc81c, \uc5b4\ub5bb\uac8c \uc0ac\uc6a9\ud558\ub294\uc9c0\uc5d0 \ub300\ud574 \ubaa8\ub450 \uc774\ud574\ud558\ub294 \uac83\uc740 \ud604\uc2e4\uc131\uc774 \ub5a8\uc5b4\uc9c4\ub2e4. \ud65c\uc6a9\ubc29\ubc95\uc5d0 \ub300\ud574 \uc880 \ub354 \uc27d\uac8c \uc811\uadfc\ud560 \uc218 \uc788\ub3c4\ub85d \uc5b4\ub5bb\uac8c \uc18c\uac1c\ud560 \uc9c0 \uc2dc\ub098\ub9ac\uc624\ub97c \uc81c\uc2dc\ud558\uace0\uc790&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/skanto.co.kr\/?p=1590\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[14,7],"tags":[162,104,163],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-sw-development","category-7","tag-collector","tag-java","tag-stream"],"_links":{"self":[{"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1590"}],"version-history":[{"count":13,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1590\/revisions"}],"predecessor-version":[{"id":1603,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1590\/revisions\/1603"}],"wp:attachment":[{"href":"https:\/\/skanto.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skanto.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}