{"id":203,"date":"2009-07-27T22:11:57","date_gmt":"2009-07-27T21:11:57","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=203"},"modified":"2009-07-27T23:50:44","modified_gmt":"2009-07-27T22:50:44","slug":"arrays-2","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/arrays-2\/","title":{"rendered":"Arrays"},"content":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables, saves on variable overload<\/p>\n<p>e.g. <\/p>\n<pre lang=\"java\">\r\nint value1 = 1;\r\nint value2 = 2;\r\nint value3 = 3;\r\nint value4 = 4;\r\nint value5 = 5;\r\nint value6 = 6;\r\n<\/pre>\n<p>and instead you could just have<\/p>\n<pre lang=\"java\">\r\nint[] values = {1,2,3,4,5,6};\r\n<\/pre>\n<p>This is example code of how to use arrays.<\/p>\n<pre lang=\"java\">\r\npublic class arraytest\r\n{\r\n       public static void main(String[] args)\r\n       {\r\n              \/\/ the main method passes in parameters from the console command line \r\n              \/\/ e.g. .\/arraytest hi there, hi there are two parameters\r\n              for (int i =0; i < args.length; i++)\r\n              {\r\n                     System.out.println(args[i]);\r\n              }\r\n              \r\n              \/\/ to create a array of numbers\r\n              int[] intarray = {0,2,3,4};\r\n              \r\n              for (int i =0 ; i < intarray.length; i++)\r\n              {\r\n                     System.out.println(intarray[i]);\r\n              }\r\n       }\r\n}\r\n<\/pre>\n<p>After compiled the above code and executed the class file that would be generated by<\/p>\n<pre class=\"consoleoutput\">\r\nJava arraytest hi there\r\n<\/pre>\n<p>The output of the program would be<\/p>\n<pre class=\"consoleoutput\">\r\nhi\r\nthere\r\n0\r\n2\r\n3\r\n4\r\n<\/pre>\n<p>But if the console command line was empty then just the number values would be outputted since they are inserted into the code and the 'hi there' was inserted manually on the command line.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables, saves on variable overload e.g. int value1 = 1; int value2 = 2; int value3 = 3; int value4 = &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/arrays-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arrays<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[401,398,400],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-linux","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}