{"id":2440,"date":"2010-12-14T19:57:14","date_gmt":"2010-12-14T14:27:14","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2440"},"modified":"2016-12-19T15:17:45","modified_gmt":"2016-12-19T09:47:45","slug":"multiple-variable-assignment-in-groovy","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/multiple-variable-assignment-in-groovy\/","title":{"rendered":"Multiple Variable Assignment in Groovy"},"content":{"rendered":"<p>In one of my project, I was in need to return multiple variables from a method. I searched and found very good Groovy way for &#8216;Multiple Assignment&#8217;, This allows us to assign multiple variables at once.<\/p>\n<p>[groovy]def (str1,str2,str3) = [&#8216;Groovy&#8217;,&#8217;and&#8217;,&#8217;Grails&#8217;]<br \/>\nassert str1 == &#8216;Groovy&#8217; &amp;amp;&amp;amp; str2 == &#8216;and&#8217; &amp;amp;&amp;amp; str3 == &#8216;Grails'[\/groovy]<\/p>\n<p>We can have types as part of the declaration<br \/>\n[groovy]<br \/>\ndef (int a,String b) = [10,&#8217;someString&#8217;]<br \/>\n[\/groovy]<\/p>\n<p>With method calls<br \/>\n[groovy]<br \/>\ndef someMethod(){<br \/>\n[5,&#8217;Hello&#8217;]<br \/>\n}<br \/>\ndef (int a,String b) = someMethod()<br \/>\n[\/groovy]<\/p>\n<p>For more information see Multiple Assignments.<\/p>\n<p>Ankur<br \/>\nankur@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my project, I was in need to return multiple variables from a method. I searched and found very good Groovy way for &#8216;Multiple Assignment&#8217;, This allows us to assign multiple variables at once. [groovy]def (str1,str2,str3) = [&#8216;Groovy&#8217;,&#8217;and&#8217;,&#8217;Grails&#8217;] assert str1 == &#8216;Groovy&#8217; &amp;amp;&amp;amp; str2 == &#8216;and&#8217; &amp;amp;&amp;amp; str3 == &#8216;Grails'[\/groovy] We can have [&hellip;]<\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":44},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2440"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2440"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2440\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}