{"id":60,"date":"2006-02-02T10:32:31","date_gmt":"2006-02-02T15:32:31","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/?p=60"},"modified":"2006-02-02T10:32:31","modified_gmt":"2006-02-02T15:32:31","slug":"java-five-oh-3-variable-arguments","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2006\/02\/02\/java-five-oh-3-variable-arguments\/","title":{"rendered":"Java Five-Oh #3: Variable Arguments"},"content":{"rendered":"<p>Variable arguments, or better known as varargs, where also introduced in Java 1.5.  The neat thing about varargs is that you can construct a single method that will accept a varied number of arguments.  When I am talking about varargs I an not talking about overloading, a single method will accept different number of parameters.  Here is how you define a method that makes use of the new vararg feature:<\/p>\n<pre>\npublic void print(String... args) {\n   for(String s : args)\n      out.println(s);\n}\n<\/pre>\n<p>In the above sample code I declare vararg method by using the &#8230; notation in after the type in the parameter list.  This method will accept zero or more string parameters.  So the following method calls will be processed by the above function:<\/p>\n<pre>\nprint(&quot;hello&quot;);\nprint(&quot;hello&quot;, &quot;hola&quot;);\n<\/pre>\n<p>The thing to note is that the args parameter is just an array that is why I was able to use the <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/01\/28\/java-five-oh-1-forin\/\">for\/in loop<\/a> construct.  I <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/01\/30\/java-five-oh-2-static-import\/\">statically imported<\/a> java.lang.System.out to make it available locally in the method implementation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variable arguments, or better known as varargs, where also introduced in Java 1.5. The neat thing about varargs is that you can construct a single method that will accept a varied number of arguments. When I am talking about varargs I an not talking about overloading, a single method will accept different number of parameters. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[15,3],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-Y","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/60"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}