Interface segregation design principle in java (SOLID & real time example)

Interface segregation principle (ISP) is one of the five principles of SOLID acronym. Interface Segregation Principle states “Clients should not be forced to depend upon interfaces that they do not use.” Client should not have the dependency on the interfaces that they do not use. Let us understand the Interface segregation principle with the help of… Read More »

STL Erase-Remove Idiom in C++ (with example)

In C++ programming paradigm, we extensively use the collection frameworks like STL, Its very common practice to remove element(s) from collection(s) like vector. The common practice is just iterate through the container to remove the desired element. But STL has builtin feature specifically to avoid this situation. Erase-Remove idiom comes in our rescue. Erase-Remove is an… 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 »

Page 20 of 43« First...10...1819202122...3040...Last »