Category Archives: List

CopyOnWriteArrayList concurrent collection in java (example)

CopyOnWriteArrayList is thread-safe variant of ArrayList. New copy of underlying array is created when any add, set (or modification) operations performed on CopyOnWriteArrayList. CopyOnWriteArrayList can be visualize as combination of words, COPY + On Write + ArrayList. New copy of underlying array is created, when any write/update/remove operation is performed on CopyOnWriteArrayList. i.e. When any… Read More »

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 or delete nodes/String objects from LinkedList collection (java/ 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. 1. Methods… 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 »

Page 1 of 212