Author: Editorial Team
-
Java Stream program to Remove Duplicate Elements from a List
Approach 1: Using Stream.distinct() Why it works: Approach 2: Using LinkedHashSet (Alternative) Why it works:
-
Java Collections.singleton() and Collections.emptySet() Tutorial
The Collections class in Java provides several utility methods to create predefined, immutable collection objects. Two commonly used methods are: Both are part of the java.util.Collections class and are often used in scenarios where read-only sets are needed or to reduce object creation overhead. 1. Collections.singleton(T element) 1.1 Overview 1.2 Syntax 1.3 Example Usage 1.4…
-
Java IdentityHashMap
The IdentityHashMap class in Java is a Map implementation that uses reference equality (==) instead of object equality (equals) for comparing keys and values. It is part of the java.util package and is intended for specialized use cases where identity-based comparison is required instead of logical equality. 1. Overview of IdentityHashMap 2. Internal Working 3.…
-
Java WeakHashMap
The WeakHashMap class in Java is part of the java.util package and is a Map implementation that uses weak references for keys. This means that entries can be automatically removed by the garbage collector when the key is no longer in ordinary use. It is often used for caching, memory-sensitive mappings, or metadata storage, where…
-
Java EnumMap Tutorial
The EnumMap class in Java is a specialized Map implementation designed specifically for use with enum keys. It is part of the java.util package and provides a highly efficient, compact representation of key-value mappings where keys are enums. Unlike general-purpose maps like HashMap or TreeMap, EnumMap is optimized for enums in both performance and memory…
-
Java EnumSet
The EnumSet class in Java is a specialized Set implementation designed specifically for use with enum types. It is part of the java.util package and provides a highly efficient, compact representation of sets of enum constants. Unlike general-purpose sets like HashSet or TreeSet, EnumSet is optimized for enums in both performance and memory usage. 1.…
-
Java NavigableMap Tutorial
The NavigableMap interface is part of the Java Collections Framework and belongs to the java.util package. It extends the SortedMap interface and provides navigation methods to find entries or keys based on their order. The most common implementation of NavigableMap is TreeMap, which stores key-value pairs in sorted order based on natural ordering of keys…
-
Java NavigableSet
The NavigableSet interface is part of the Java Collections Framework and is included in the java.util package. It extends the SortedSet interface and adds navigation methods for querying the set based on closest matches. It is most commonly implemented by the TreeSet class, which stores elements in a sorted, ascending order and allows efficient log(n)…
-
java.util.Collections
The java.util.Collections class is a utility class in Java that provides static methods for operating on or returning collections such as List, Set, and Map. It is part of the java.util package. Unlike java.util.Collection (an interface for actual collection objects), Collections contains helper methods to manipulate collection objects, such as sorting, searching, reversing, synchronizing, and…
-
Collection Hierarchy – Diagram
Here’s a detailed textual diagram of the Java Collection Framework hierarchy with explanations at each level. I’ve included interfaces, abstract classes, and commonly used implementations.
