{"id":2202,"date":"2017-04-14T09:34:39","date_gmt":"2017-04-14T09:34:39","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2202"},"modified":"2017-04-26T14:18:23","modified_gmt":"2017-04-26T14:18:23","slug":"java-arrays","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/java-arrays\/","title":{"rendered":"Dissection of  ArrayList"},"content":{"rendered":"<p><strong>Two Dimensional Arrays<\/strong> (Array of Arrays)<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n \/\/Seating Arrangement for 20 Seats\r\n int arrSeating&#x5B;]&#x5B;] = new int&#x5B;4]&#x5B;5];\r\n\r\n \/\/No of Items Produced in Hr By Days in Month\r\n int arrProdHrByDaysInMonth&#x5B;]&#x5B;] = new int&#x5B;30]&#x5B;24];\r\n<\/pre>\n<p><strong>Two Dimensional Arrays<\/strong>(Array of Arrays of Arrays)<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n \/\/No of Items Produced in Hr By Days in Month by Month\r\n int arrProdHrByDaysInMonth&#x5B;]&#x5B;]&#x5B;] = new int&#x5B;12]&#x5B;30]&#x5B;24];\r\n<\/pre>\n<p><strong>Jagged Arrays<\/strong><br \/>\narray of arrays such that member arrays can be of different sizes<\/p>\n<p><strong>Looping through ArrayList<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n         \t\/\/Iterate over Collection\r\n\t\tfor (Iterator iterator = arrNames.iterator(); iterator.hasNext();) {\r\n\t\t\tString object = (String) iterator.next();\r\n\t\t\tSystem.out.println(object);\r\n\t\t}\t\t\t\r\n\t\t\r\n\t\t\/\/Iterate over array or Collection\r\n\t\tfor (String string : arrNames) {\r\n\t\t\tSystem.out.println(string);\r\n\t\t}\t\t\r\n\t\t\r\n\t\t\/\/Iterate over array \r\n\t\tfor (int i = 0; i &lt; arrNames.size(); i++) {\r\n\t\t\tSystem.out.println(arrNames.get(i));\r\n\t\t}\r\n\t\t\r\n\t\t\/\/Iterate over array using Temporary Variable\r\n\t\tfor (int i = 0; i &lt; arrNames.size(); i++) {\r\n\t\t\tString string = arrNames.get(i);\r\n\t\t\tSystem.out.println(string);\r\n\t\t}\r\n<\/pre>\n<p><strong>Which one of the Above method is Faster?<\/strong><br \/>\nAll the methods are of same speed since the Traditional for loop uses Iterator inside.The performance difference is noted when there is change in data structure while doing random access like linkedlist is slower than arraylist when you use a traditional for loop since to traverse a 6th element in list it should start from all again<\/p>\n<p><strong>When there is a sorted Array and you should do a search in the sorted array then using BinarySearch is faster than Linear Search<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two Dimensional Arrays (Array of Arrays) \/\/Seating Arrangement for 20 Seats int arrSeating&#x5B;]&#x5B;] = new int&#x5B;4]&#x5B;5]; \/\/No of Items Produced in Hr By Days in Month int arrProdHrByDaysInMonth&#x5B;]&#x5B;] = new int&#x5B;30]&#x5B;24]; Two Dimensional Arrays(Array of Arrays of Arrays) \/\/No of Items Produced in Hr By Days in Month by Month int arrProdHrByDaysInMonth&#x5B;]&#x5B;]&#x5B;] = new int&#x5B;12]&#x5B;30]&#x5B;24];&hellip; <a href=\"https:\/\/codethataint.com\/blog\/java-arrays\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-2202","post","type-post","status-publish","format-standard","hentry","category-arrays"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2202"}],"version-history":[{"count":10,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2202\/revisions"}],"predecessor-version":[{"id":2254,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2202\/revisions\/2254"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}