Category: linkedlist
How to add elements in a LinkedList in Java
In this article we will discuss how to add elements in LinkedList and then display them. Lets create a LinkedList of String i.e. Advertisements List<String> listOfStr = new LinkedList<>(); To add elements in LinkedList we will use its add() function i.e. boolean add(E e) add() member function of LinkedList always appends the element in the …
How to add elements at a particular index in LinkedList
In this article we will discuss how to add elements at a particular index or position in a LinkedList in Java. add() member function of LinkedList always appends the element at the end of LinkedList. Now suppose we don’t want to add element at the end of Linked List instead of it we want to add element somewhere …
How to add elements at a particular index in LinkedListRead More
Java LinkedList Tutorial
LinkedList is a kind of List used to store elements. Its an ordered collection i.e. elements added at a position in LinkedList will remain in that position till modified by user. It internally uses a doubly linked list datastructure implementation i.e. each element is stored at separate node. Each node has a reference to previous and …
How to iterate over a LinkedList in Java
In this article we will discuss how to iterate over a LinkedList Collection in Java and access objects. To fetch the Iterator from a LinkedList object use following member function, Advertisements ListIterator<E> listIterator(); It will return ListIterator object that implements Iterator that provides functions to iterate over the LinkedList object. It manages an internal Cursor which is …
How to iterate LinkedList in reverse or backward direction
In this article we will discuss how to iterate over a LinkedList in reverse order. Method 1 : Using Descending Iterator Iterator<E> descendingIterator() Descending Iterator returns the Iterator that points to the end of of List i.e. LinkedList<String> listOfStr = new LinkedList<>(); // Get Descending List Iterator from List Object Iterator<String> listItReverse = listOfStr.descendingIterator(); Now calling function …
How to iterate LinkedList in reverse or backward directionRead More