Java Program to Implement Unrolled Linked List Last Updated : 11 Apr, 2023 Comments Improve Suggest changes Like Article Like Report An Unrolled Linked List is a special type of Linked List in which each node stores an array of elements, unlike a simple linked list. Here we use an ArrayList and a constructor that initializes the size of the Unrolled Linked List. Elements are added to the first Node until it is filled and then a new Node is created with the same size. The Node class has two methods namely A constructorAn insert method which takes an integer as a parameter. Implementation: Adding elements to the unrolled linked listDeleting elements from an unrolled linked list Example 1: Adding elements to Unrolled Linked List Java // Java Program to implement Unrolled Linked List // Importing all input output classes import java.io.*; // Importing all utility classes from // java.util package import java.util.*; // Class 1 // Main class class GFG { // Nested static class static class Node { // Member variables of static nested class int size; ArrayList<Integer> array; // Initializing next as NULL Node next = null; // Method 1 // Of nested static class // To compute over size Node(int size) { // This keyword refers to current object itself this.size = size; // Storing ArrayList in an array array = new ArrayList<>(); } // Method 2 // To insert element in an array void insert(int n) { // If array is having empty spaces if (array.size() < size) { // Add element from List to array array.add(n); } // If array is already full else { // Array size is zero if (next == null) { // Create a new Node and start inserting // elements next = new Node(size); next.insert(n); } // If array is defined else { // Directly start inserting elements next.insert(n); } } } } // Main driver method public static void main(String args[]) { // Creating an object of nested static class // inside the main() method // Maximum N elements will be printed in a row // N is passed as an parameter to the Node // N = 3 for illustration, do change and // observe how the output varies Node x = new Node(3); // Adding custom input elements // using the insert() method x.insert(10); x.insert(20); x.insert(30); x.insert(40); x.insert(50); x.insert(60); x.insert(70); // System.out.println(x.array); // System.out.println(x.next.array); // System.out.println(x.next.next.array); // If condition holds true // If there are elements left to be inserted while (x != null) { // Print and display the elements System.out.println(x.array); // Moving to next element x = x.next; } } } Output[10, 20, 30] [40, 50, 60] [70] Example 2: Deleting elements from an unrolled linked list Java // Java Program to implement Unrolled Linked List // Importing all input output classes import java.io.*; // Importing all utility classes from // java.util package import java.util.*; // Class 1 // Main class class GFG { // Nested static class static class Node { // Member variables of nested class int size; ArrayList<Integer> array; // Initially next is pointing to head Node next = null; // Constructor of static nested class Node(int size) { // This keyword refers to current object itself this.size = size; // Assigning current List element // to an array array = new ArrayList<>(); } // Method 1 // Of static nested class void insert(int n) { // If there is space in an array if (array.size() < size) { // Add elements to an array array.add(n); } // Condition check over array else { // If no array exists, it means // head is still pointing to NULL if (next == null) { // Create a new node next = new Node(size); // Now, start inserting elements next.insert(n); } // If next is NOT-NULL else { // Start filling array directly next.insert(n); } } } // Method 2 // Of static nested class boolean delete(int n) { if (array.contains(n)) { array.remove(array.indexOf(n)); return true; } else { if (next == null) { return false; } else { next.delete(n); } return true; } } } // Mai driver method public static void main(String args[]) { // Creating an object of Nodetype where // 3 as an argument represents maximum elements // to be displayed in a row Node x = new Node(3); // Adding elements to the above object // Custom input entries x.insert(10); x.insert(20); x.insert(30); x.insert(40); x.insert(50); x.insert(60); x.insert(70); // System.out.println(x.array); // System.out.println(x.next.array); // System.out.println(x.next.next.array); // Display message System.out.println( "After Inserting all elements : "); // Creating an object of static nested class Node temp = x; while (temp != null) { System.out.println(temp.array); temp = temp.next; } // Display message System.out.println("Deleting 50 :"); // Deleting a random element from above added // Say it be 50 x.delete(50); // Using the temp variable so that // value is not lost temp = x; // Condition check // If temp viable is NOT-NULL while (temp != null) { // Print and display the temp array // be it one element or many System.out.println(temp.array); // Moving to the next node using // standard way 'next' in linkedList temp = temp.next; } } } OutputAfter Inserting all elements : [10, 20, 30] [40, 50, 60] [70] Deleting 50 : [10, 20, 30] [40, 60] [70] Comment More infoAdvertise with us Next Article Java Program to Implement Unrolled Linked List varunkedia Follow Improve Article Tags : Java Java Programs java-LinkedList Practice Tags : Java Similar Reads Java Program to Implement Triply Linked List Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers. In this post, methods to insert a new node in a linked list are discussed. A node can be inserted in three ways either at the front of the linked list or after a given node or at the 8 min read Java Program to Implement LinkedList API Linked List is a part of the Collection framework That is present in java.util package. This class is an implementation of the LinkedList data structure which is a linear data structure in which the elements are not stored in contiguous locations and every element is a separate object with a data pa 10 min read Program to unfold a folded linked list A linked list L0 -> L1 -> L2 -> ..... -> LN can be folded as L0 -> LN -> L1 -> LN - 1 -> L2 -> ..... Given a folded linked list, the task is to unfold and print the original linked list Examples: Input: 1 -> 6 -> 2 -> 5 -> 3 -> 4 Output: 1 2 3 4 5 6 Input: 1 15+ min read Java Program to Get Elements of a LinkedList Linked List is a linear data structure, in which the elements are not stored at the contiguous memory locations. Here, the task is to get the elements of a LinkedList. 1. We can use get(int variable) method to access an element from a specific index of LinkedList: In the given example, we have used 4 min read Java Program to Implement LinkedBlockingQueue API LinkedBlockingQueue API is an optionally-bounded queue based on linked nodes. It orders the elements in FIFO(First In First Out) order. The head of this queue is the element that has been there in the queue for the longest time and the tail of the queue is the element that has been in the queue for 6 min read Java Program to Search an Element in a Linked List Prerequisite: LinkedList in java LinkedList is a linear data structure where the elements are not stored in contiguous memory locations. Every element is a separate object known as a node with a data part and an address part. The elements are linked using pointers or references. Linked Lists are pre 5 min read Java Program to Implement VList VList is a data structure that combines fast indexing of arrays with the easy extension of singly-linked lists. VList generally supports the following functions. Insert ElementGet Element at index kClear ListDisplay ListEtc. VList has rows connected as Singly Linked List where the Nth row contains m 3 min read Can We Implement Xor Linked List in Java? As we all can depict from the below figure that doubly LinkedList requires two link fields in order to store the address of the next node and the address of the right node Right? So XOR Linked list Typically acts as Doubly LinkedList. Each node of XOR Linked List requires only a single pointer field 3 min read Java Program to Implement LinkedTransferQueue API LinkedTransferQueue is a queue that orders elements FIFO (first-in-first-out) with respect to any given producer. The head of the queue is that element that has been on the queue the longest time for some producer. The tail of the queue is that element that has been on the queue the shortest time fo 5 min read Java Program To Delete Middle Of Linked List Given a singly linked list, delete the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the linked list should be modified to 1->2->4->5 If there are even nodes, then there would be two middle nodes, we need to delete the second middle element. For example, if g 4 min read Like