Posts

Showing posts with the label Code example List

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 ...

ArrayList in Java

An ArrayList is a group of common elements. It is concrete implementation of List interface. ArrayList has ordered elements in which order they added. There are several methods which we will discuss here today. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package net . raj . test ; import java.util.ArrayList ; import java.util.List ; public class ArrayListImpl { public static void main ( String [] args ) { // Declare an ArrayList List < string > list = new ArrayList <>(); list . add ( "one" ); list . add ( "two" ); list . add ( "three" ); list . add ( "four" ); System . out . println ( "Sample ArrayList 1:: " + list . toString ()); } } Output: Sample ArrayList 1:: [one, two, three, four] In the above example we saw that we added few elements when print those items we saw the same order in which they added to list. It shows the basic property ...