Linked-List in Java
Java’s LinkedList
class is a versatile and commonly used data structure that implements the List
and Deque
interfaces while extending the AbstractSequentialList. Below is the list of operations performed on a java linked list,
Operations |
Syntax |
---|---|
Declaration |
LinkedList<DataType> myLinkedList = new LinkedList<>(); |
Inserting X at Head |
myLinkedList.addFirst(X); |
Removing from Head |
myLinkedList.removeFirst(); |
Inserting X at Tail |
myLinkedList.addLast(X); |
Removing from Tail |
myLinkedList.removeLast(); |
Inserting Element X |
myLinkedList.add(X); |
Inserting Element X at index i |
myLinkedList.add(i, X); |
Removing Element X |
myLinkedList.remove(X); |
Removing Element at index i |
myLinkedList.remove(i); |
Getting Element at index i |
DataType value = myLinkedList.get(i) |
Setting Element at index i to X |
myLinkedList.set(i, X); |
Checking for Existence of element X |
boolean containsX = myLinkedList.contains(X); |
Size of LinkedList |
int size = myLinkedList.size(); |
Conversion to Array |
DataType[] array = myLinkedList.toArray(new DataType[0]); |
A Quick Guide on DSA and Competitive Coding in Java
Data Structures and Algorithms (DSA) are the building blocks of efficient and optimized software solutions, especially in the realm of competitive coding. In this quick guide, we’ll explore key concepts of DSA using Java, a versatile and widely used programming language.
Table of Content
- Arrays In Java:
- Strings In Java:
- Stack in Java:
- Queue in Java:
- Linked-List in Java:
- Hash Table in java:
- Maps In Java:
- Set In Java
- Heap in Java: