Posts

Showing posts with the label LinkedList in Java

Custom LinkedList Implementation

Image
The Linkedlist represents the chain of data nodes as list in java. The current node has the address or connection with the next node in single linked list and of previous node also in double linked list. To build custom linkedlist, please follow below 3 steps: 1. First, we need to construct the structure of linked list 2. Second, implement the operations of the linked list in another class 3. Third, test the functionality The source code of program Output: 12->454->89->1 12->454->1 45->12->454->1->23 abc->raj->kiran abc->raj 65->Gyan Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element from list How to declare Linked List and Implement LinkedList Traversal In Reverse Sequential Order ...

Fetch elements from LinkedList

There are several methods given in the linked list to retrieve the inserted elements. Each method has its own importance. E.g. If user wants to retieve the first element from the list, it can choose among get(int index), getFirst(), element(), peek() or peekFirst() methods but there usages are different like get(int index) method provides the element from any given position(index) whereas getFirst(), element(), peek() or peekFirst() methods returns only first element from the list. Let us see the different usages of these methods: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 package net . raj . test . list ; import java.util.LinkedList ; /** * @author Raj Saxena * */ public class LinkedListRetrieveImpl { public static void main ( String ... args ) { // Declare an LinkedList LinkedList < String > list = new LinkedList <...

List Traversal

There are so many questions comes into mind when we go to the coding floor and starts writing the code for list like how to traverse the list in java? What are the different ways to traverse a list? Which is the best way? Which way needs to be followed? Here, we will try to find out the answers of these questions. There are two ways to traverse the list - forward or backward. The list has given methods like next and previous. We can iterate the list starting from a specific index too. Output : Iterating list in forward direction... one two three four five Iterating list in backward direction... five four three two one Iterating list from specified position... three four five Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element...

LinkedList Declaration

Image
An LinkedList is a group of common elements. It is concrete implementation of List and Deque interface. It permits all elements including null. Output : Original LinkedList :: [one, two, three, four, five] Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element from list How to declare Linked List and Implement LinkedList Traversal In Reverse Sequential Order ArrayList in Java How to declare array list in java Some other interesting blogs: IOT and Big Data Technologies Sustainability Cloud