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:

Similar Reads

Arrays In Java:

Arrays are used to store multiple values in a single variable using a contiguous blocks of memory instead of declaring separate variables for each value....

Strings In Java:

...

Stack in Java:

Strings are the type of objects that can store the character of values and in Java, every character is stored in 16 bits i,e using UTF 16-bit encoding. A string acts the same as an array of characters in Java....

Queue in Java:

The Stack class in Java extends the Vector class, which is a dynamic array-like data structure. Common stack operations are supported, such as push, pop, peek, and isEmpty....

Linked-List in Java:

A queue is a First-In-First-Out (FIFO) data structure used to manage elements in a way that the first element added is the first one to be removed. The Queue interface can be implemented using LinkedList or ArrayDeque. In Java, the Java Collections Framework provides several types of queues that can be used based on different requirements. Here are some commonly used queue types in Java: Linked List Queue Priority Queue Array Deque Blocking Queue Concurrent Linked Queue Linked Blocking Queue Array Blocking Queue...

Hash Table 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,...

Maps In Java

In Java, a Hashtable is a legacy class that is part of the Java Collections Framework and implements the Map interface. It provides a way to store key-value pairs, where each key must be unique. Here are the key operations performed on a Java Hashtable:...

Set In Java

In Java, maps are part of the Java Collections Framework and are used to store key-value pairs. The primary interface for maps is the Map interface. There are several implementations of the Map interface in Java, each with its own characteristics. Here are some common. HashMap: O(1) time complexity for basic operations. TreeMap: O(log N) time complexity for basic operations. LinkedListMap : O(1) time complexity for basic operations. Let us see the basic operations performed in these....

Heap in Java:

In Java, a Set is a part of the Java Collections Framework and is an interface that extends the Collection interface. It represents a collection of unique elements, meaning that no duplicate elements are allowed. The Set interface is implemented by several classes in Java among them the most common ones are: HashSet TreeSet...