{"id":5788,"date":"2021-10-14T10:54:32","date_gmt":"2021-10-14T10:54:32","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5788"},"modified":"2023-07-31T04:59:11","modified_gmt":"2023-07-31T04:59:11","slug":"how-to-implement-generic-linkedlist-in-java","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/","title":{"rendered":"How to Implement Generic LinkedList in java"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\" alt=\"\" \/><\/p>\n<p>Mastering the Linked List data structure is of utmost importance when gearing up for interviews. A comprehensive grasp of Linked Lists can offer significant advantages during coding interviews.<\/p>\n<p>In this tutorial, we will learn how to implement a generic linked list in java that can work with multiple data types. A Linked List is a linear Data Structure, which consists of a group of nodes, which are stored at random addresses. Each node consists of 2 parts:<\/p>\n<p><strong>Data<\/strong>: The Data which is stored at the particular address.<br \/>\n<strong>Reference<\/strong>: The address of the next node of the linked list.<\/p>\n<h2>What is a Generic Linked List in Java?<\/h2>\n<p>A generic linked list, also known as a template linked list or a polymorphic linked list, is a data structure that allows for the storage of elements of different data types in a single linked list. In programming languages that support generics or templates, such as C++ or Java, a generic linked list can be created using templates or generic classes.<\/p>\n<p>The idea behind a generic linked list is to provide a flexible and reusable data structure that can hold elements of various data types without the need to create separate linked lists for each data type. This allows for code reusability and simplifies the implementation of algorithms that need to work with different types of data.<\/p>\n<p>For example, a generic linked list could store integers, strings, or custom objects, making it a versatile tool in various programming applications. The ability to work with different data types while maintaining the structure and functionality of a linked list makes generic linked lists a powerful and efficient data structure in modern programming languages.<\/p>\n<p>In this article, we will learn how to implement a generic LinkedList class that can work with multiple data types.<\/p>\n<p>We will implement the following member functions in our LinkedList class:<\/p>\n<ul>\n<li>addNode(T data) &#8211; This method will add a new element at the end of LinkedList.<\/li>\n<li>addNode(int position, T data) &#8211; This method will add a new element at a particular position in the LinkedList.<\/li>\n<li>removeNode(T key) &#8211; This method will remove a node from the LinkedList.<\/li>\n<li>clearList() &#8211; This method will clear the whole LinkedList.<\/li>\n<li>isEmpty() &#8211; This method will check whether a LinkedList is empty or not.<\/li>\n<li>length() &#8211; This method will return the length of the LinkedList.<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: Here, T represents the type of data which will be stored in the linked list.<\/p>\n<p><strong>Example 1<\/strong>: Implementation of add(T data), add(int position, T data), removeNode(T key)<\/p>\n<h3>Code:<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5789 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_5789 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_5789 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5789 .wpsm_nav-tabs > li.active > a, #tab_container_5789 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5789 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_5789 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_5789 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5789 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5789 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5789 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5789 .wpsm_nav-tabs > li > a:hover , #tab_container_5789 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_5789 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_5789 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_5789 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_5789 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_5789 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_5789 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_5789 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5789 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_5789 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5789 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_5789 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_5789\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5789\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5789_1\" aria-controls=\"tabs_desc_5789_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5789\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_5789_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass node&lt;t&gt; {\r\n\r\n    \/\/ Stores data of the node\r\n    T data;\r\n    \/\/ Store address of the node\r\n    node&lt;t&gt; next;\r\n\r\n    \/\/ Constructor\r\n    node(T data) {\r\n\r\n        this.data = data;\r\n        this.next = null;\r\n    }\r\n}\r\n\r\nclass list&lt;t&gt; {\r\n\r\n    \/\/ Head of the node\r\n    node&lt;t&gt; head;\r\n\r\n    \/\/Store length of the linked list\r\n    private int len = 0;\r\n\r\n    \/\/ Constructor\r\n    list() {\r\n        this.head = null;\r\n    }\r\n\r\n    \/\/ Method addNode(T data): This method add a new element at the end\r\n    void addNode(T data) {\r\n\r\n        \/\/ creating a new generic node\r\n        node&lt;t&gt; temp = new node&lt;&gt;(data);\r\n\r\n        \/\/ check if list is empty\r\n        if (this.head == null) {\r\n            head = temp;\r\n        }\r\n\r\n        \/\/ if list exists\r\n        else {\r\n\r\n            node&lt;t&gt; X = head;\r\n\r\n            \/\/ Iterate the List\r\n            while (X.next != null) {\r\n                X = X.next;\r\n            }\r\n\r\n            X.next = temp;\r\n        }\r\n\r\n        \/\/ Increase the len after adding new node\r\n        len++;\r\n    }\r\n\r\n    \/\/ Method addNode(int pos,T data): It will add a new element at a particular position\r\n    void addNode(int pos, T data) {\r\n\r\n        \/\/ Check position if its valid or not\r\n        if (pos &gt; len + 1) {\r\n\r\n            System.out.println(&quot;Position not found&quot;);\r\n            return;\r\n        }\r\n\r\n        \/\/ if new node is to be added in the beginning\r\n        if (pos == 1) {\r\n            node&lt;t&gt; temp = head;\r\n            head = new node&lt;t&gt;(data);\r\n            head.next = temp;\r\n            return;\r\n        }\r\n\r\n        \/\/ Temporary node to store previous head\r\n        node&lt;t&gt; temp = head;\r\n        node&lt;t&gt; prev = new node&lt;t&gt;(null);\r\n        \/\/ Interating\r\n        while (pos - 1 &gt; 0) {\r\n            prev = temp;\r\n            temp = temp.next;\r\n            pos--;\r\n        }\r\n        prev.next = new node&lt;t&gt;(data);\r\n        prev.next.next = temp;\r\n    }\r\n\r\n    \/\/ Method removeNode(T key): It will remove a node from the LinkedList\r\n    void removeNode(T key) {\r\n        node&lt;t&gt; prev = new node&lt;&gt;(null);\r\n        prev.next = head;\r\n        node&lt;t&gt; next = head.next;\r\n        node&lt;t&gt; temp = head;\r\n\r\n        \/\/ This will check whether the value is present or not\r\n        boolean exists = false;\r\n\r\n        if (head.data == key) {\r\n            head = head.next;\r\n\r\n            \/\/ Node is present which we will want to remove\r\n            exists = true;\r\n        }\r\n\r\n        while (temp.next != null) {\r\n\r\n            \/\/ Convert the value to be compared to string\r\n            if (String.valueOf(temp.data).equals(String.valueOf(key))) {\r\n\r\n                prev.next = next;\r\n                exists = true;\r\n\r\n                break;\r\n            }\r\n            prev = temp;\r\n\r\n            temp = temp.next;\r\n\r\n            next = temp.next;\r\n        }\r\n\r\n        if (exists == false &amp;&amp; String.valueOf(temp.data).equals(String.valueOf(key))) {\r\n            prev.next = null;\r\n\r\n            exists = true;\r\n        }\r\n\r\n        \/\/ When the node which we want to delete exists\r\n        if (exists) {\r\n\r\n            \/\/ reduce the len of linked list\r\n            len--;\r\n        }\r\n\r\n        \/\/ If it does not exist\r\n        else {\r\n            System.out.println(&quot;Not found in linked list&quot;);\r\n        }\r\n    }\r\n\r\n    public String toString() {\r\n\r\n        String S = &quot;{&quot;;\r\n\r\n        node&lt;t&gt; X = head;\r\n\r\n        if (X == null)\r\n            return S + &quot;}&quot;;\r\n\r\n        while (X.next != null) {\r\n            S += String.valueOf(X.data) + &quot;-&gt;&quot;;\r\n            X = X.next;\r\n        }\r\n\r\n        S += String.valueOf(X.data);\r\n        return S + &quot;}&quot;;\r\n    }\r\n}\r\n\r\npublic class LinkedList {\r\n    public static void main(String[] args) {\r\n        \/\/ Creating new linked list of int type\r\n        list&lt;integer&gt; list1 = new list&lt;&gt;();\r\n        list1.addNode(1);\r\n        list1.addNode(25);\r\n        list1.addNode(69);\r\n\r\n        list1.addNode(2, 35);\r\n\r\n        System.out.println(&quot;Original list 1: &quot; + list1);\r\n\r\n        list1.removeNode(69);\r\n\r\n        System.out.println(&quot;New list 1 after removing a node from the list: &quot; + list1);\r\n\r\n        System.out.println();\r\n\r\n        \/\/ Create new linked list of string type\r\n        list&lt;string&gt; list2 = new list&lt;&gt;();\r\n\r\n        list2.addNode(&quot;prepbytes&quot;);\r\n        list2.addNode(&quot;Algorithm&quot;);\r\n\r\n        System.out.println(&quot;Original list 2: &quot; + list2);\r\n\r\n        list2.addNode(1, &quot;Data&quot;);\r\n\r\n        System.out.println(&quot;New list 2 after adding element: &quot; + list2);\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5789 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_5789 a\"),jQuery(\"#tab-content_5789\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong>:<br \/>\nOriginal list 1: {1-&gt;35-&gt;25-&gt;69}<br \/>\nNew list 1 after removing a node from the list: {1-&gt;35-&gt;25}<\/p>\n<p>Original list 2: {prepbytes-&gt;Algorithm}<br \/>\nNew list 2 after adding element: {Data-&gt;prepbytes-&gt;Algorithm}<\/p>\n<p><strong>Example 2<\/strong>: Implementation of addNode(T data), isEmpty(), clearList(), length().<br \/>\nCode:<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5790 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_5790 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_5790 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5790 .wpsm_nav-tabs > li.active > a, #tab_container_5790 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5790 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_5790 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_5790 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5790 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5790 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5790 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5790 .wpsm_nav-tabs > li > a:hover , #tab_container_5790 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_5790 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_5790 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_5790 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_5790 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_5790 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_5790 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_5790 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5790 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_5790 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5790 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_5790 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_5790\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5790\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5790_1\" aria-controls=\"tabs_desc_5790_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5790\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_5790_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass node&lt;t&gt; {\r\n\r\n    \/\/ Stores data of the node\r\n    T data;\r\n    \/\/ Store address of the node\r\n    node&lt;t&gt; next;\r\n\r\n    \/\/ Constructor\r\n    node(T data)\r\n    {\r\n\r\n        this.data = data;\r\n        this.next = null;\r\n    }\r\n}\r\nclass list&lt;t&gt; {\r\n\r\n    \/\/ Head of the node\r\n    node&lt;t&gt; head;\r\n    \r\n    private int len = 0;\r\n\r\n    \/\/constructor\r\n    list() { this.head = null; }\r\n    \r\n    \/\/ Method addNode(T data): This method adds a new element at the end\r\n    void addNode(T data)\r\n    {\r\n\r\n        \/\/ Creating a new generic node\r\n        node&lt;t&gt; temp = new node&lt;&gt;(data);\r\n\r\n        if (this.head == null) {\r\n            head = temp;\r\n        }\r\n\r\n        else {\r\n\r\n            node&lt;t&gt; X = head;\r\n\r\n            \/\/ Iterate the List\r\n            while (X.next != null) {\r\n                X = X.next;\r\n            }\r\n\r\n            X.next = temp;\r\n        }\r\n\r\n        \/\/ Increase the len after adding new node\r\n        len++;\r\n    }\r\n    \/\/ Method clearList(): It will clear the Linked List\r\n    void clearList()\r\n    {\r\n        head = null;\r\n        len = 0;\r\n    }\r\n \r\n    \/\/ Method isEmpty(): It will check whether a list is empty or not\r\n    boolean isEmpty()\r\n    {\r\n        if (head == null) {\r\n            return true;\r\n        }\r\n        return false;\r\n    }\r\n    \/\/ Method length(): It will return the length of the linked list\r\n    int length() { \r\n        return this.len; }\r\n\r\n    public String toString()\r\n    {\r\n\r\n        String S = &quot;{&quot;;\r\n\r\n        node&lt;t&gt; X = head;\r\n\r\n        if (X == null)\r\n            return S + &quot;}&quot;;\r\n\r\n        while (X.next != null) {\r\n            S += String.valueOf(X.data) + &quot;-&gt;&quot;;\r\n            X = X.next;\r\n        }\r\n\r\n        S += String.valueOf(X.data);\r\n        return S + &quot;}&quot;;\r\n    }\r\n}\r\n\r\npublic class LinkedList {\r\n    public static void main(String[] args)\r\n    {\r\n        \/\/ Creating new  linked list\r\n        list&lt;integer&gt; list1 = new list&lt;&gt;();\r\n        list1.addNode(1);\r\n        list1.addNode(25);\r\n        list1.addNode(69);\r\n        \r\n        \r\n\r\n        System.out.println(&quot;Original list 1 :&quot;+list1);\r\n\r\n        System.out.println(&quot;Length of linked list :&quot;+list1.length());\r\n\r\n        System.out.println(&quot;is list empty:&quot;+list1.isEmpty());\r\n        \r\n        list1.clearList();\r\n        System.out.println(&quot;list 1 after clearList method:&quot;+list1);\r\n        \r\n        System.out.println();\r\n\r\n        \/\/ Create new linked list of string type\r\n        list&lt;string&gt; list2 = new list&lt;&gt;();\r\n\r\n        list2.addNode(&quot;prepbytes&quot;);\r\n        list2.addNode(&quot;Algorithm&quot;);\r\n        \r\n        System.out.println(&quot;Original list 2: &quot;+list2);\r\n        System.out.println(&quot;Length of linked list: &quot;+list2.length());\r\n\r\n        System.out.println(&quot;is list empty: &quot;+list2.isEmpty());\r\n        \r\n        list2.clearList();\r\n        System.out.println(&quot;list 2 after clearList method: &quot;+list2);\r\n    }\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5790 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_5790 a\"),jQuery(\"#tab-content_5790\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong>:<br \/>\nOriginal list 1 :{1-&gt;25-&gt;69}<br \/>\nLength of linked list :3<br \/>\nis list empty:false<br \/>\nlist1 after clearList method:{}<\/p>\n<p>Original list 2: {prepbytes-&gt;Algorithm}<br \/>\nLength of linked list: 2<br \/>\nis list empty: false<br \/>\nlist 2 after clearList method: {}<\/p>\n<p><strong>Time complexity<\/strong>: O(N) for addNode() and removeNode() operations and O(1) for clearList(), isEmpty() and length() operations.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nThis process of implementation of generic linked list in Java provides a versatile and reusable data structure that can store elements of different data types. By utilizing generics, developers can create a single linked list implementation capable of accommodating various data types, promoting code reusability, and ensuring type safety. Implementing a generic linked list in Java is a fundamental skill for programmers, allowing them to create efficient and adaptable data structures suitable for a wide range of applications.<\/p>\n<p>Here are some FAQs related to the implementation of generic linked list in Java.<\/p>\n<h2>FAQs related to how to implement a generic linked list in Java:<\/h2>\n<p><strong>Q1. What is a generic linked list in Java?<\/strong><br \/>\nA generic linked list in Java is a data structure that can hold elements of any data type using generics. It allows for the creation of a single linked list implementation that can store diverse data types efficiently and safely.<\/p>\n<p><strong>Q2. How do you declare a generic linked list class in Java?<\/strong><br \/>\nTo declare a generic linked list class in Java, use angle brackets and a placeholder type (e.g., <T>). For example, class LinkedList<T> { &#8230; } would create a generic linked list class with a type parameter T.<\/p>\n<p><strong>Q2. How do I declare a generic linked list in Java?<\/strong><br \/>\nTo declare a generic linked list in Java, you can use the following syntax: LinkedList<T>, where T is the placeholder for the data type.<\/p>\n<p><strong>Q3. Can I store any data type in a generic linked list?<\/strong><br \/>\nYes, a generic linked list can store elements of any data type, including primitive data types, objects, or custom data types defined by classes.<\/p>\n<p><strong>Q4. How does Java&#8217;s generics ensure type safety in a generic linked list?<\/strong><br \/>\nJava&#8217;s generics provide compile-time type checking, ensuring that only elements of the specified data type (or its subclasses) can be inserted into the generic linked list.<\/p>\n<p><strong>Q5. How do generics ensure type safety in a linked list?<\/strong><br \/>\nGenerics ensure type safety in a linked list by enforcing that elements added to the list must match the specified type. The Java compiler performs type-checking at compile-time, reducing the risk of runtime errors due to data type mismatches.<\/p>\n<p><strong>Q6. Can I use custom objects with a generic linked list?<\/strong><br \/>\nYes, generic linked lists can store custom objects. Simply provide the custom class type as the generic parameter when declaring the linked list class.<\/p>\n<p><strong>Q7. How do I implement basic operations like insertion and deletion in a generic linked list?<\/strong><br \/>\nIn a generic linked list implementation, you can define methods for inserting, deleting, searching, and other common operations. These methods can utilize the generic type parameter to handle elements of any data type.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mastering the Linked List data structure is of utmost importance when gearing up for interviews. A comprehensive grasp of Linked Lists can offer significant advantages during coding interviews. In this tutorial, we will learn how to implement a generic linked list in java that can work with multiple data types. A Linked List is a [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-5788","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Implement Generic LinkedList in java | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"Learn how to implement a generic Linked List in Java using Class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Implement Generic LinkedList in java | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to implement a generic Linked List in Java using Class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-14T10:54:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-31T04:59:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"How to Implement Generic LinkedList in java\",\"datePublished\":\"2021-10-14T10:54:32+00:00\",\"dateModified\":\"2023-07-31T04:59:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\"},\"wordCount\":979,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\",\"name\":\"How to Implement Generic LinkedList in java | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\",\"datePublished\":\"2021-10-14T10:54:32+00:00\",\"dateModified\":\"2023-07-31T04:59:11+00:00\",\"description\":\"Learn how to implement a generic Linked List in Java using Class.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Implement Generic LinkedList in java\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Implement Generic LinkedList in java | PrepBytes Blog","description":"Learn how to implement a generic Linked List in Java using Class.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/","og_locale":"en_US","og_type":"article","og_title":"How to Implement Generic LinkedList in java | PrepBytes Blog","og_description":"Learn how to implement a generic Linked List in Java using Class.","og_url":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-14T10:54:32+00:00","article_modified_time":"2023-07-31T04:59:11+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"How to Implement Generic LinkedList in java","datePublished":"2021-10-14T10:54:32+00:00","dateModified":"2023-07-31T04:59:11+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/"},"wordCount":979,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/","url":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/","name":"How to Implement Generic LinkedList in java | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png","datePublished":"2021-10-14T10:54:32+00:00","dateModified":"2023-07-31T04:59:11+00:00","description":"Learn how to implement a generic Linked List in Java using Class.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012058122-Article_198.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/how-to-implement-generic-linkedlist-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"How to Implement Generic LinkedList in java"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=5788"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5788\/revisions"}],"predecessor-version":[{"id":17415,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5788\/revisions\/17415"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}