Java CopyOnWriteArraySet example. This class is a thread-safe variant of HashSet which uses a underlying CopyOnWriteArrayList for all of its operations.
Java CopyOnWriteArrayList is a thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array. It’s immutable snapshot style iterator method uses a reference to the state of the array at the point that the iterator was created. This helps in […]
Java TransferQueue is a concurrent blocking queue implementation in which producers may wait for receipt of messages by consumers. LinkedTransferQueue class is an implementation of TransferQueue in Java. TransferQueue may be useful for example in message passing applications in which producers sometimes (using method transfer()) await receipt of elements by consumers invoking take or poll, […]
ArrayBlockingQueue class is Java concurrent and bounded blocking queue implementation backed by an array. It orders elements FIFO (first-in-first-out). The head of the ArrayBlockingQueue is that element that has been on the queue the longest time. The tail of the ArrayBlockingQueue is that element that has been on the queue the shortest time. New elements […]
Java PriorityBlockingQueue class is concurrent blocking queue data structure implementation in which objects are processed based on their priority. The “blocking” part of the name is added to imply the thread will block waiting until there’s an item available on the queue.
Java PriorityQueue example. PriorityQueue class is a queue data structure implementation in which objects are processed based on their priority.
Java Spliterator interface is an internal iterator that breaks the stream into the smaller parts. These smaller parts can be processed in parallel. In real life programming, we may never need to use Spliterator directly. Under normal operations, it will behave exactly same as Java Iterator. The Java collection classes provide default stream() and parallelStream() […]
Java ListIterator interface is bi-directional iterator which is used to iterate over the elements of list in either direction previous or next.
Java Iterator interface used to iterate over the elements in a collection (list, set or map). It helps to retrieve the specified collection elements one by one and perform operations over each element. 1. Java Iterator interface All Java collection classes provide iterator() method which return the instance of Iterator to walk over the elements […]
Java Comparator interface used to sort a array or list of objects based on custom order. Custom ordering of elements is imposed by implementing Comparator.compare() method in the objects.
Java Comparable interface used to sort a array or list of objects based on their natural order. Natural ordering of elements is imposed by implementing it’s compareTo() method in the objects. 1. Java Comparable interface Java Comparable interface imposes a total ordering on the objects of each class that implements it. This ordering is referred […]
Java LinkedList class is doubly-linked list implementation of the List and Deque interfaces. It implements all optional list operations, and permits all elements (including null). Table of Contents 1. LinkedList Hierarchy 2. LinkedList Features 3. LinkedList Constructors 4. LinkedList Methods 5. LinkedList Example 6. LinkedList Usecases 7. LinkedList Performance 8. ArrayList vs LinkedList 9. Conclusion […]
Java TreeSet class extends AbstractSet and implements NavigableSet interface. It is very similar to HashSet class, except it stores the element in sorted order.
Java LinkedHashSet class extends HashSet and implements Set interface. It is very very similar to HashSet class, except if offers the predictable iteration order.
Java HashSet class implements the Set interface, backed by a hash table(actually a HashMap instance). If does not offer any guarantees as to the iteration order, and allows null element.
Java Hashtable class is an implementation of hash table data structure. It is very much similar to HashMap but it is synchronized while HashMap is not.
TreeMap in Java is used to store key-value pairs very similar to HashMap class. Difference is that TreeMap provides an efficient way to store key/value pairs in sorted order. It is a red-Black tree based NavigableMap implementation. In this Java TreeMap tutorial, we will learn about TreeMap class, it’s methods, usecases and other important details. […]
LinkedHashMap in Java is used to store key-value pairs very similar to HashMap class. Difference is that LinkedHashMap maintains the order of elements inserted into it while HashMap is unordered. In this Java collection tutorial, we will learn about LinkedHashMap class, it’s methods, usecases and other important details. Table of Contents 1. LinkedHashMap Hierarchy 2. […]
Learn to create clone of a HashMap in Java. We will see the java programs to create shallow copy and deep copy of a HashMap. Read More : A guide to cloning in Java 1. Clone HashMap – shallow copy 1.1. HashMap clone() method The best way to create shallow clone of hashmap is to […]
Learn to remove duplicate elements in ArrayList in Java using different techniques such as LinkedHashSet in Collections framework and using java 8 stream apis. 1. Remove duplicate elements in arraylist using LinkedHashSet The LinkedHashSet is the best approach for removing duplicate elements in an arraylist. LinkedHashSet does two things internally : Remove duplicate elements Maintain […]