Category Archives: List

Add, remove, retain, sort & important methods of linkedlist (java / example)

The LinkedList class extends AbstractSequentialList and implements the List interface. Given a LinkedList in java containing elements. We will discuss following operations of linkedlist with examples Remove Add Retain Sort Iterate Get Contains And Clear Program – Add, remove, retain, sort etc. methods of linkedlist package org.learn.collection.list.linkedlist; import java.util.Collections; import java.util.LinkedList; import java.util.ListIterator; public class DemoLinkedList… Read More »

Sort elements of linkedlist in java (ascending & descending order)

The LinkedList class extends AbstractSequentialList and implements the List interface. Given an LinkedList, we would like to sort elements of linkedlist in ascending and descending order. Program – Sort linked list in ascending & descending order package org.learn.collection.list.linkedlist; import java.util.Collections; import java.util.LinkedList; public class SortElementInLinkedList { public static void main(String[] args) { LinkedList<String> LinkedList = new LinkedList<>();… Read More »

Iterate or loop LinkedList collection of String objects in java (with example)

Linked list in java is a doubly-linked list. Insertion order is maintained in a linked list. LinkedList extends AbstractSequentialList class & implements List, Deque,  Cloneable, Serializable interfaces. LinkedList class is not thread safe. In multi threaded environment, it should be synchronized externally. The iterators returned by LinkedList class’s iterator and listIterator methods are fail-fast. LinkedList class… Read More »

Retain & remove elements/ nodes of linkedlist collection (Java/ example)

Given a LinkedList collection in java, we would like retain certain elements or nodes of linkedlist. We would like to remove rest of elements from linkedlist. The LinkedList class extends AbstractSequentialList and implements the List interface. LinkedList class have following method to retain elements/ nodes. boolean retainAll(Collection<?> c) Retains only the elements in this list… Read More »

Remove element(s) from linkedlist in java (with example)

The LinkedList class extends AbstractSequentialList and implements the List interface. LinkedList has following methods to remove element(s). E remove() Retrieves and removes the head (first element) of this list. E remove(int index) Removes the element at the specified position in this list. boolean remove(Object o) Removes the first occurrence of the specified element from this list,… Read More »

Add or insert elements/ nodes to linkedlist in java (with example)

Linked list in java is a doubly-linked list. Insertion order is maintained in a linked list. LinkedList extends AbstractSequentialList class & implements List, Deque,  Cloneable, Serializable interfaces. LinkedList class is not thread safe. In multi threaded environment, it should be synchronized externally. The iterators returned by LinkedList class’s iterator and listIterator methods are fail-fast. LinkedList class… Read More »

Add, Remove, Retain, Sort & other important methods of arraylist in java

Given an arraylist, we would demonstrate the following operations of arraylist. Remove Add Retain Sort Iterate Get Contains And Clear Program – Add, sort, iterate, get methods of arraylist in java package org.learn.collection.list.arrayList; import java.util.ArrayList; import java.util.Collections; import java.util.ListIterator; public class DemoArrayList { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<>(); arrayList.add(“archery”); arrayList.add(“badminton”);… Read More »

Page 1 of 212