{"id":2715,"date":"2017-07-13T11:58:55","date_gmt":"2017-07-13T09:58:55","guid":{"rendered":"http:\/\/www.itersdesktop.com\/?p=2715"},"modified":"2017-07-13T12:08:34","modified_gmt":"2017-07-13T10:08:34","slug":"combine-two-lists-in-groovy","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/","title":{"rendered":"Combine two lists in Groovy"},"content":{"rendered":"<p><em>K\u1ebft h\u1ee3p ho\u1eb7c n\u1ed1i hai hay nhi\u1ec1u danh s\u00e1ch \u0111\u01b0\u1ee3c cho r\u1eb1ng xu\u1ea5t hi\u1ec7n kh\u00e1 th\u01b0\u1eddng xuy\u00ean trong l\u1eadp tr\u00ecnh. B\u00e0i b\u00e1o n\u00e0y cho b\u1ea1n bi\u1ebft c\u00e1ch \u0111\u1ec3 k\u1ebft h\u1ee3p hai danh s\u00e1ch trong ng\u00f4n ng\u1eef Groovy theo nh\u1eefng c\u00e1ch kh\u00e1c nhau.<\/em><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a147e18c2f45\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a147e18c2f45\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-with-addall\" >Combine lists with addAll<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-using-the-plus-operator\" >Combine lists using the plus operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-with-addall-2\" >Combine lists with addAll<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-using-the-plus-operator-2\" >Combine lists using the plus operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-with-addall-3\" >Combine lists with addAll<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.itersdesktop.com\/vi\/2017\/07\/13\/combine-two-lists-in-groovy\/#combine-lists-using-the-plus-operator-3\" >Combine lists using the plus operator<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"combine-lists-with-addall\"><\/span>Combine lists with addAll<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <span class=\"lang:default decode:true crayon-inline \">java.util.ArrayList.addAll(Collection&lt;? extends E&gt; c)<\/span>\u00a0 method appends all of the elements from the specified collection (the second list) to the end of the current list (the first list), in the order that they are returned by the specified collection&#8217;s Iterator.<\/p>\n<pre class=\"lang:go decode:true\">def fruits = [\"Apple\", \"Banana\", \"Cherry\"]\r\ndef newFruits = [\"Pear\", \"Plum\", \"Strawberry\"]\r\nfruits.addAll(newFruits)\r\nprintln fruits<\/pre>\n<p>The output looks like the following<\/p>\n<pre class=\"lang:default decode:true \">[Apple, Banana, Cherry, Pear, Plum, Strawberry]<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"combine-lists-using-the-plus-operator\"><\/span>Combine lists using the plus operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Naturally we can think about the plus operator when combining two lists. The plus operator will return a new list containing all the elements of the two lists while and the <span class=\"lang:default decode:true crayon-inline \">addAll<\/span>\u00a0 method appends the elements of the second list to the end of the first one.<\/p>\n<pre class=\"lang:default decode:true \">def fruits = [\"Apple\", \"Banana\", \"Cherry\"]\r\ndef newFruits = [\"Pear\", \"Plum\", \"Strawberry\"]\r\nprintln fruits + newFruits<\/pre>\n<p>Obviously, the output is the same as the one using addAll method.<\/p>\n<p>I hope you could be interested in this useful article. If you have any queries, feel free to drop me a message underneath.<\/p>","protected":false},"excerpt":{"rendered":"<p>K\u1ebft h\u1ee3p ho\u1eb7c n\u1ed1i hai hay nhi\u1ec1u danh s\u00e1ch \u0111\u01b0\u1ee3c cho r\u1eb1ng xu\u1ea5t hi\u1ec7n kh\u00e1 th\u01b0\u1eddng xuy\u00ean trong l\u1eadp tr\u00ecnh. B\u00e0i b\u00e1o n\u00e0y cho b\u1ea1n bi\u1ebft c\u00e1ch \u0111\u1ec3 k\u1ebft h\u1ee3p&hellip; <\/p>\n","protected":false},"author":2,"featured_media":2717,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[595],"tags":[628,626,629,627,347],"class_list":["post-2715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-groovy","tag-combination","tag-combine","tag-concat","tag-concatenation","tag-list"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/comments?post=2715"}],"version-history":[{"count":5,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2715\/revisions"}],"predecessor-version":[{"id":2721,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2715\/revisions\/2721"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media\/2717"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media?parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/categories?post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/tags?post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}