






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the Java LinkedList class, its relationship to AbstractSequentialList and List/Deque interfaces, and its key features. The document also covers the constructors of LinkedList, methods for adding and removing elements, and the differences between LinkedList and ArrayList. It includes examples of reversing a LinkedList and a comparison of the two data structures.
Typology: Summaries
1 / 11
This page cannot be seen from the preview
Don't miss anything!







LinkedList() It is used to construct an empty list.
LinkedList(Collection<? extends E> c) It is used to construct a list containing the elements of the specified collection, in the order, they are returned by the collection's iterator.
Method Description boolean add(E e) It is used to append the specified element to the end of a list. e.g: LinkedList
int indexOf(Object o) It is used to return the index in a list of the first occurrence of the specified element, or -1 if the list does not contain any element. int lastIndexOf(Object o) It is used to return the index in a list of the last occurrence of the specified element, or -1 if the list does not contain any element. ListIterator
E poll() It retrieves and removes the first element of a list. E pollFirst() It retrieves and removes the first element of a list, or returns null if a list is empty. E pollLast() It retrieves and removes the last element of a list, or returns null if a list is empty. E pop() It pops an element from the stack represented by a list. void push(E e) It pushes an element onto the stack represented by a list. E remove() It is used to retrieve and removes the first element of a list. E remove(int index) It is used to remove the element at the specified position in a list. boolean remove(Object o) It is used to remove the first occurrence of the specified element in a list. E removeFirst() It removes and returns the first element from a list.
JAVA LINKEDLIST EXAMPLE TO REVERSE A LIST OF ELEMENTS package linkedlistmanipulation; import java.util.*; public class LinkedListManipulation { public static void main(String[] args) { LinkedList
DIFFERENCE BETWEEN ARRAYLIST AND LINKEDLIST ArrayList LinkedList ArrayList internally uses a dynamic array to store the elements. LinkedList internally uses a doubly linked list to store the elements. Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory. An ArrayList class can act as a list only because it implements List only. LinkedList class can act as a list and queue both because it implements List and Deque interfaces. ArrayList is better for storing and accessing data. LinkedList is better for manipulating data.