What is Java LinkedList?
A Linked List is a type of linear data structure. It differs from arrays in that elements are not kept in contiguous locations. Instead, Nodes in a linked list are linked using pointers.
Linked List Creation
Structure of a node
There are two parts to each linked list node:
Data: Data that get stored at a specific location.
Reference: Provides the address of the following linked list node.
Creation & Insertion Operations
Our goal here is to create a java linked list and insert a new node to the end it. For example, we have a Linked List 1→3→5→7→9 and want to add 11 to the end. Adding 11 to the end of the given linked list will update it to 1→3→5→7→9->11.
Here we will learn how to remove the first occurrence of a given node from the linked list, i.e., remove the first occurrence of a given key.
For example, if we have a Linked List 1→3→5→7→9, we want to remove the first occurrence of node 3 (key = 3) from the linked list.
By deleting the first instance of the node with value 3 from the linked list, we will end up with: 1→5→7→9.