<div dir="ltr" style="text-align: left;" trbidi="on">
<ul>
<li><i><b>LinkedList </b></i>class extends <i><b>AbstractSequentialList </b></i>and implements <b><i>List</i></b>, <b><i>Deque </i></b>and <i><b>Queue</b></i> interface.</li>
<li>It can be used as <i><b>List</b></i>, stack or <b><i>Queue </i></b>as it implements all the related interfaces.</li>
<li>It can contain duplicate elements and is not synchronized.</li>
<li>maintains insertion order.</li>
<li>not synchronized.</li>
<li>No random access.</li>
<li>manipulation fast because no shifting needs to be occurred.</li>
</ul>
<div align='center' id="ads-id"></div>
<p><b>The <i>LinkedList </i>class supports two constructors:</b> </p>
<pre class="highlight" name="code">//The first constructor builds an empty linked list: 
LinkedList( ) 
 
//The following constructor builds a linked list that is initialized with the elements of the collection c. 
LinkedList(Collection c) 
</pre>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0.8em 0px 1em; orphans: auto; padding: 0px; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/linkedlist.jpg"/></div>
<p>
<b>Methods in <i>LinkedList</i>: </b><br />
Apart from the methods inherited from its parent classes, <b><i>LinkedList </i></b>defines following methods:</div>
<p></p>
<table class="src" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f7f7f7; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); color: black; font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 8px 0px; orphans: auto; padding: 0px; text-align: start; text-indent: 0px; text-transform: none; vertical-align: top; white-space: normal; widows: auto; width: 560px; word-spacing: 0px;">
<tbody style="margin: 0px; padding: 0px;">
<tr style="margin: 0px; padding: 0px;">
<th style="background-color: #eeeeee; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px; text-align: left;">SN</th>
<th style="background-color: #eeeeee; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px; text-align: left;">Methods with Description</th>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">1</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">void add(int index, Object element)</b><br />
Inserts the specified element at the specified position index in this list. Throws <b><i>IndexOutOfBoundsException </i></b>if the specified index is is out of range (index <; 0 || index >; size()).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">2</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean add(Object o) ;</b><br />
Appends the specified element to the end of this list.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">3</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean addAll(Collection c)</b><br />
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection&#8217;s iterator. Throws <i><b>NullPointerException </b></i>if the specified collection is null.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">4</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean addAll(int index, Collection c) ;</b><br />
Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws <i><b>NullPointerException </b></i>if the specified collection is null.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">5</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">void addFirst(Object o)</b><br />
Inserts the given element at the beginning of this list.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">6</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">void addLast(Object o) ;</b><br />
Appends the given element to the end of this list.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">7</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">void clear() ;</b><br />
Removes all of the elements from this list.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">8</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object clone() ;</b><br />
Returns a shallow copy of this <i><b>LinkedList</b></i>.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">9</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean contains(Object o) ;</b><br />
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">10</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object get(int index) ;</b><br />
Returns the element at the specified position in this list. Throws <b><i>IndexOutOfBoundsException </i></b>if the specified index is is out of range (index <; 0 || index >;= size()).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">11</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object getFirst() ;</b><br />
Returns the first element in this list. Throws <b><i>NoSuchElementException </i></b>if this list is empty.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">12</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object getLast() ;</b><br />
Returns the last element in this list. Throws <i><b>NoSuchElementException </b></i>if this list is empty.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">13</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">int indexOf(Object o) ;</b><br />
Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">14</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">int lastIndexOf(Object o)</b><br />
Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">15</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">ListIterator listIterator(int index)</b><br />
Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Throws <b><i>IndexOutOfBoundsException </i></b>if the specified index is is out of range (index <; 0 || index >;= size()).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">16</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object remove(int index) ;</b><br />
Removes the element at the specified position in this list. Throws <b><i>NoSuchElementException </i></b>if this list is empty.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">17</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean remove(Object o) ;</b><br />
Removes the first occurrence of the specified element in this list. Throws <b><i>NoSuchElementException </i></b>if this list is empty. Throws <i><b>IndexOutOfBoundsException </b></i>if the specified index is is out of range (index <; 0 || index >;= size()).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">18</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object removeFirst() ;</b><br />
Removes and returns the first element from this list. Throws <i><b>NoSuchElementException </b></i>if this list is empty.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">19</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object removeLast() ;</b><br />
Removes and returns the last element from this list. Throws <i><b>NoSuchElementException </b></i>if this list is empty.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">20</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object set(int index, Object element) ;</b><br />
Replaces the element at the specified position in this list with the specified element. Throws <i><b>IndexOutOfBoundsException </b></i>if the specified index is is out of range (index <; 0 || index >;= size()).</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">21</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">int size() ;</b><br />
Returns the number of elements in this list.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">22</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object[] toArray() ;</b><br />
Returns an array containing all of the elements in this list in the correct order. Throws <i><b>NullPointerException </b></i>if the specified array is null.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">23</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object[] toArray(Object[] a) ;</b><br />
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.</td>
</tr>
</tbody>
</table>
<p>
<b>Example of <i>LinkedList</i>:</b></p>
<pre class="highlight" name="code">import java.util.*; 
 
public class LinkedListDemo { 
 
 public static void main(String args[]) { 
 // create a linked list 
 LinkedList ll = new LinkedList(); 
 // add elements to the linked list 
 ll.add("F"); 
 ll.add("B"); 
 ll.add("D"); 
 ll.add("E"); 
 ll.add("C"); 
 ll.addLast("Z"); 
 ll.addFirst("A"); 
 ll.add(1, "A2"); 
 System.out.println("Original contents of ll: " + ll); 
 
 // remove elements from the linked list 
 ll.remove("F"); 
 ll.remove(2); 
 System.out.println("Contents of ll after deletion: " 
 + ll); 
 
 // remove first and last elements 
 ll.removeFirst(); 
 ll.removeLast(); 
 System.out.println("ll after deleting first and last: " 
 + ll); 
 
 // get and set a value 
 Object val = ll.get(2); 
 ll.set(2, (String) val + " Changed"); 
 System.out.println("ll after change: " + ll); 
 } 
} 
</pre>
<p>
<b>output:</b></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/05/linkedlist.png"/></div>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;">
<b>Java Collections Tutorial</b></p>
<ol style="text-align: left;">
<li><b><a href="https://dineshonjava.com/arraylist-class-in-java-collection/">ArrayList class</a></b></li>
<li><b><a href="https://dineshonjava.com/listiterator-interface-in-collection/">ListIterator interface</a></b></li>
<li><b><a href="https://dineshonjava.com/hashset-class-in-collection/">HashSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/linkedhashset-class-in-collection/">LinkedHashSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/treeset-classin-collection/">TreeSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-hashset-and-treeset/">Difference between TreeSet &; HashSet</a></b></li>
<li><b><a href="https://dineshonjava.com/map-interface-in-collection/">Map interface</a></b></li>
<li><b><a href="https://dineshonjava.com/hashmap-class-in-collection-framework/">HashMap class</a></b></li>
<li><b><a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">How does work HashMap?</a> </b></li>
<li><b><a href="https://dineshonjava.com/difference-between-treemap-vs-hashmap/">Difference between TreeMap vs HashMap</a></b></li>
<li><b><a href="https://dineshonjava.com/linkedhashmap-class-in-collection/">LinkedHashMap class</a></b></li>
<li><b><a href="https://dineshonjava.com/treemap-class-in-collection-framework/">TreeMap class</a></b></li>
<li><b><a href="https://dineshonjava.com/hashtable-class-in-collection-framework/">Hashtable class</a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-hashmap-and/">Difference between HashMap and HashTable in Java</a></b></li>
<li><b><a href="https://dineshonjava.com/sorting-in-collection-framework/">Sorting</a></b></li>
<li><b><a href="https://dineshonjava.com/java-comparable-and-comparator/">Comparable interface</a></b></li>
</ol>
</div>
<p></p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/arraylist-class-in-java-collection/">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/">Index </a>||  ; >;>;<a href="https://dineshonjava.com/listiterator-interface-in-collection/">Next</a> >;>;</b></div>
<p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/arraylist-class-in-java-collection/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/listiterator-interface-in-collection/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '467'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…