{"id":23218,"date":"2021-03-27T09:50:10","date_gmt":"2021-03-27T13:50:10","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/linked-list-and-iterator-in-java-root-by-sayed-ahmed\/"},"modified":"2021-03-27T09:50:10","modified_gmt":"2021-03-27T13:50:10","slug":"linked-list-and-iterator-in-java-root-by-sayed-ahmed","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=23218","title":{"rendered":"Linked List and Iterator in Java #Root #By Sayed Ahmed"},"content":{"rendered":"<p>By Sayed: 8 [use Firefox or IE with large font size]<\/p>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<pre>\/*\r\n * LinkedList.java\r\n *\r\n * Created on January 10, 2008, 8:51 PM\r\n *\r\n * To change this template, choose Tools | Template Manager\r\n * and open the template in the editor.\r\n *\/\r\n\r\npackage linkedlist;\r\n\r\nimport java.util.List;\r\nimport java.util.LinkedList;\r\nimport java.util.Iterator;\r\nimport java.util.ListIterator;\r\nimport java.util.Collections;\r\nimport java.util.Random;\r\n\r\n\/**\r\n *\r\n * @author Sayed\r\n *\/\r\npublic class LinkedListTest {\r\n    \r\n    \/** Creates a new instance of LinkedList *\/\r\n    public LinkedListTest() {\r\n    }\r\n    \r\n    \/**\r\n     *Example operations using linked lists\r\n     *\/\r\n    \r\n    public void linkedListOperation(){\r\n        \r\n        final int MAX = 10;\r\n        int counter = 0;\r\n\r\n        \/\/create two linked lists\r\n        List listA = new LinkedList();\r\n        List listB = new LinkedList();\r\n\r\n        \/\/store data in the linked list A\r\n        for (int i = 0; i &lt; MAX; i++) {\r\n            System.out.println(\"  - Storing Integer(\" + i + \")\");\r\n            listA.add(new Integer(i));\r\n        }\r\n       \r\n        \/\/print data from the linked list using iterator \r\n        Iterator it = listA.iterator();\r\n        while (it.hasNext()) {\r\n            System.out.println(it.next());\r\n        }\r\n\r\n        \/\/print data from the linked list using listIterator. \r\n        counter = 0;\r\n        ListIterator liIt = listA.listIterator();\r\n        while (liIt.hasNext()) {\r\n            System.out.println(\"Element [\" + counter + \"] = \" + liIt.next());\r\n            System.out.println(\"  - hasPrevious    = \" + liIt.hasPrevious());\r\n            System.out.println(\"  - hasNext        = \" + liIt.hasNext());\r\n            System.out.println(\"  - previousIndex  = \" + liIt.previousIndex());\r\n            System.out.println(\"  - nextIndex      = \" + liIt.nextIndex());\r\n            System.out.println();\r\n            counter++;\r\n        }\r\n\r\n\r\n        \/\/retrieve data from the linked list using index\r\n        for (int j=0; j &lt; listA.size(); j++) {\r\n            System.out.println(\"[\" + j + \"] - \" + listA.get(j));\r\n        }\r\n\r\n        \/\/find the location of an element\r\n        int locationIndex = listA.indexOf(\"5\");\r\n        System.out.println(\"Index location of the String \"5\" is: \" + locationIndex);  \r\n\r\n        \/\/find the first and the last location of an element\r\n        System.out.println(\"First occurance search for String \"5\".  Index =  \" + \r\n\t\tlistA.indexOf(\"5\"));\r\n        System.out.println(\"Last Index search for String \"5\".       Index =  \" + \r\n\t\tlistA.lastIndexOf(\"5\"));\r\n\r\n        \/\/create a sublist from the list \r\n        List listSub = listA.subList(10, listA.size());\r\n        System.out.println(\"New Sub-List from index 10 to \" + listA.size() + \": \" + \r\n\t\tlistSub);\r\n\r\n        \/\/sort the sub-list\r\n        System.out.println(\"Original List   : \" + listSub);\r\n        Collections.sort(listSub);\r\n        System.out.println(\"New Sorted List : \" + listSub);\r\n        System.out.println();\r\n\r\n        \/\/reverse the new sub-list\r\n        System.out.println(\"Original List     : \" + listSub);\r\n        Collections.reverse(listSub);\r\n        System.out.println(\"New Reversed List : \" + listSub);\r\n        System.out.println();\r\n\r\n        \/\/check to see if the lists are empty\r\n        System.out.println(\"Is List A empty?   \" + listA.isEmpty());\r\n        System.out.println(\"Is List B empty?   \" + listB.isEmpty());\r\n        System.out.println(\"Is Sub-List empty? \" + listSub.isEmpty());\r\n        \r\n        \/\/compare two lists\r\n        System.out.println(\"A=B? \" + listA.equals(listB));        \r\n        System.out.println();\r\n\r\n        \/\/Shuffle the elements around in some Random order for List A\r\n        Collections.shuffle(listA, new Random());\r\n\r\n        \/\/convert a list into an array\r\n        Object[] objArray = listA.toArray();\r\n        for (int j=0; j &lt; objArray.length; j++) {\r\n            System.out.println(\"Array Element [\" + j + \"] = \" + objArray[j]);\r\n        }\r\n\r\n        \/\/clear listA\r\n        System.out.println(\"List A   (before) : \" + listA);        \r\n        System.out.println();\r\n        listA.clear();\r\n        System.out.println(\"List A   (after)  : \" + listA);        \r\n        System.out.println();\r\n        \r\n    }\r\n    \/**\r\n     * @param args the command line arguments\r\n     *\/\r\n    public static void main(String[] args) {\r\n        \/\/ TODO code application logic here\r\n        LinkedListTest listExample = new LinkedListTest();\r\n        listExample.linkedListOperation();\r\n    }\r\n    \r\n}\r\n<\/pre>\n<p> From: http:\/\/sitestree.com\/?p=3673<br \/> Categories:Root, By Sayed Ahmed<br \/>Tags:<br \/> Post Data:2016-09-15 14:18:33<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Sayed: 8 [use Firefox or IE with large font size] \/* * LinkedList.java * * Created on January 10, 2008, 8:51 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. *\/ package linkedlist; import java.util.List; import java.util.LinkedList; import java.util.Iterator; import java.util.ListIterator; import java.util.Collections; &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=23218\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-23218","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10102,"url":"http:\/\/bangla.sitestree.com\/?p=10102","url_meta":{"origin":23218,"position":0},"title":"J2SE : LinkedList and Iterators in Java","author":"","date":"July 31, 2015","format":false,"excerpt":"\/* \u00a0* LinkedList.java \u00a0* \u00a0* Created on January 10, 2008, 8:51 PM \u00a0* \u00a0* To change this template, choose Tools | Template Manager \u00a0* and open the template in the editor. \u00a0*\/ package linkedlist; import java.util.List; import java.util.LinkedList; import java.util.Iterator; import java.util.ListIterator; import java.util.Collections; import java.util.Random; \/** \u00a0* \u00a0* @author\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65912,"url":"http:\/\/bangla.sitestree.com\/?p=65912","url_meta":{"origin":23218,"position":1},"title":"Linked List and Iterator in Java #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 17, 2021","format":false,"excerpt":"\/* * LinkedList.java * * Created on January 10, 2008, 8:51 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. *\/package linkedlist;import java.util.List;import java.util.LinkedList;import java.util.Iterator;import java.util.ListIterator;import java.util.Collections;import java.util.Random;\/** * * @author Sayed *\/public class LinkedListTest { \/** Creates a\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26862,"url":"http:\/\/bangla.sitestree.com\/?p=26862","url_meta":{"origin":23218,"position":2},"title":"LinkedList and Iterators in Java #Programming Code Examples #Java\/J2EE\/J2ME #J2SE","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"\/* * LinkedList.java * * Created on January 10, 2008, 8:51 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. *\/ package linkedlist; import java.util.List; import java.util.LinkedList; import java.util.Iterator; import java.util.ListIterator; import java.util.Collections; import java.util.Random; \/** * * @author\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65876,"url":"http:\/\/bangla.sitestree.com\/?p=65876","url_meta":{"origin":23218,"position":3},"title":"Set, TreeSet, Iterator in Java #Java Short Notes #Blog","author":"Author-Check- Article-or-Video","date":"July 16, 2021","format":false,"excerpt":"\/* * TreeSetExample.java * *Illustrates mathematical set operations * * Created on January 10, 2008, 9:28 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. *\/package treesetexample;import java.util.Set;import java.util.TreeSet;import java.util.Iterator;\/** * * @author Sayed *\/public class TreeSetExample { \/**\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":23218,"position":4},"title":"Multithreaded Graphics and Double Buffering #Programming Code Examples #Java\/J2EE\/J2ME #Java Threads","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { ... public void run() { Ship s; for(int\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65938,"url":"http:\/\/bangla.sitestree.com\/?p=65938","url_meta":{"origin":23218,"position":5},"title":"EJB 3: Entity Bean Basic #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Plain Java objects with persistence storage. They are not remotable and must be accessed through the new javax.persistence.EntityManager service. An entity bean implementation is provided in the following three files\/classesBeansOrder.javaLineItem.javaEntity ManagerShoppingCartBean.java\/\/Order.javaimport javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.OneToMany;import javax.persistence.Table;import javax.persistence.Id;import javax.persistence.CascadeType;import javax.persistence.FetchType;import java.util.ArrayList;import java.util.Collection;@Entity@Table(name = \"PURCHASE_ORDER\")public class Order implements\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23218"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23218\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23218"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}