{"id":144,"date":"2013-07-10T06:19:46","date_gmt":"2013-07-10T06:19:46","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=144"},"modified":"2013-07-10T10:02:31","modified_gmt":"2013-07-10T10:02:31","slug":"list-notes","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/list-notes\/","title":{"rendered":"List Notes"},"content":{"rendered":"<ul>\n<li>List maintains elements in Particular Sequence.<\/li>\n<li>Two types of List 1.ArrayList and 2.LinkedList<\/li>\n<li>ArrayList is faster while accessing elements but slower while Insertion and Deletion<\/li>\n<li>LinkedList is slow in random access but faster during insertion and deletion<\/li>\n<\/ul>\n<p>Operations in ArrayList<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Fruits\r\n{\t\r\n  String Name = &quot;Fruit&quot;;\r\n}\r\n\r\nclass Apple extends Fruits\r\n{\t\r\n public Apple()\r\n {\r\n   Name = &quot;Apple&quot;;\r\n }\r\n}\r\n\r\nclass Orange extends Fruits\r\n{\t\r\n public Orange()\r\n {\r\n  Name = &quot;Orange&quot;;\r\n }\r\n}\r\n\r\nclass Mango extends Fruits\r\n{\t\r\n public Mango()\r\n {\r\n  Name = &quot;Mango&quot;;\r\n }\r\n}\r\n<\/pre>\n<p><strong>Adding Element &#8211; List.add()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nList&lt;Fruits&gt; arrFruits = new ArrayList&lt;Fruits&gt;();\r\nFruits objApple  = new Apple();\r\nFruits objMango  = new Mango();\r\narrFruits.add(objApple);\r\narrFruits.add(objMango);\r\n<\/pre>\n<p><strong>Removing Element &#8211; List.remove()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\narrFruits.remove(objApple);\r\n<\/pre>\n<p><strong>Removing by Index &#8211; List.remove()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\narrFruits.remove(1);\r\n<\/pre>\n<p><strong>Index of Element &#8211; List.indexOf()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\narrFruits.indexOf(objMango);\r\n<\/pre>\n<p><strong>Index of Element &#8211; List.indexOf()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\narrFruits.indexOf(objMango);\r\n<\/pre>\n<p><strong>SubList &#8211; List.subList(StartPOS, EndPOS)<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nList&lt;Fruits&gt; arrNewFruits = arrFruits.subList(0,2);\r\n<\/pre>\n<p><strong>containsAll &#8211; NewList.containsAll(OrgList)<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n arrNewFruits.containsAll(arrFruits);\r\n<\/pre>\n<p><strong>set Value at Index<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n arrNewFruits.set(1, new Orange());\r\n<\/pre>\n<p><strong>removeAll<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n arrFruits.removeAll(arrFruits);\r\n<\/pre>\n<p><strong>addAll<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n arrFruits.addAll(arrNewFruits);\r\n<\/pre>\n<p><strong>retainAll &#8211; set Intersection Operation<br \/>\nretainAll performs set Interscetion Operation by taking Two ArrayList. It Retains Boolean true if intersection finds element false otherwise.   <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nList&lt;Integer&gt; arrNums1 = new ArrayList&lt;Integer&gt;();\r\narrNums1.add(1);\r\narrNums1.add(2);\r\narrNums1.add(3);\r\n\t\t\r\nList&lt;Integer&gt; arrNums2 = new ArrayList&lt;Integer&gt;();\r\narrNums2.add(1);\r\n\r\nSystem.out.println(arrNums1.retainAll(arrNums2));\r\nSystem.out.println(arrNums1);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>List maintains elements in Particular Sequence. Two types of List 1.ArrayList and 2.LinkedList ArrayList is faster while accessing elements but slower while Insertion and Deletion LinkedList is slow in random access but faster during insertion and deletion Operations in ArrayList class Fruits { String Name = &quot;Fruit&quot;; } class Apple extends Fruits { public Apple()&hellip; <a href=\"https:\/\/codethataint.com\/blog\/list-notes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[21],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-list"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/144","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=144"}],"version-history":[{"count":12,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}