{"id":1791,"date":"2016-09-27T09:01:04","date_gmt":"2016-09-27T09:01:04","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1791"},"modified":"2016-09-27T09:01:04","modified_gmt":"2016-09-27T09:01:04","slug":"collections-basics","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/collections-basics\/","title":{"rendered":"Collections Basics"},"content":{"rendered":"<p><strong>Points to Note<\/strong><\/p>\n<ol>\n<li>ArrayList allows NULL values many times<\/li>\n<li>Set and HashMap allows NULL once<\/li>\n<li>In HashMap the values will be overwritten when keys are same<\/li>\n<\/ol>\n<p><strong>List <\/strong>An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.<\/p>\n<p><strong>Map<\/strong>An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.<\/p>\n<p><strong>Test.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class Test\r\n{\r\n public static void main(String&#x5B;] args) \r\n {\r\n List&lt;String&gt; arrNames = new ArrayList&lt;String&gt;();\r\n \r\n arrNames.add(&quot;Hello&quot;);\r\n arrNames.add(null);\r\n arrNames.add(null);\r\n arrNames.add(&quot;Hi&quot;); \r\n System.out.println(&quot;List - &quot;+arrNames.size());\r\n \r\n Map hmTest = new HashMap();\r\n hmTest.put(&quot;1&quot;, &quot;mugil&quot;);\r\n hmTest.put(null, null);\r\n hmTest.put(null, null);\r\n hmTest.put(&quot;1&quot;, &quot;vannan&quot;);\r\n System.out.println(&quot;HashMap - &quot;+ hmTest.size());\r\n \r\n Set&lt;Integer&gt; setTest = new HashSet&lt;Integer&gt;();\r\n \r\n setTest.add(new Integer(&quot;10&quot;));\r\n setTest.add(new Integer(&quot;20&quot;));\r\n setTest.add(new Integer(&quot;10&quot;));\r\n \r\n System.out.println(&quot;Set - &quot;+ setTest.size());\r\n }\r\n}\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\nList - 4\r\nHashMap - 2\r\nSet - 2\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Points to Note ArrayList allows NULL values many times Set and HashMap allows NULL once In HashMap the values will be overwritten when keys are same List An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can&hellip; <a href=\"https:\/\/codethataint.com\/blog\/collections-basics\/\">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":[193],"tags":[],"class_list":["post-1791","post","type-post","status-publish","format-standard","hentry","category-interview-questions-java"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1791","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=1791"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1791\/revisions"}],"predecessor-version":[{"id":1792,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1791\/revisions\/1792"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}