Browse by Topic

Popular

Latest

Latest Java Posts

Diagram showing how HashSet uses hashCode to find buckets and equals to compare elements.
Java

Java HashSet equals and hashCode Explained

Learn how Java HashSet uses equals() and hashCode() for duplicate detection, how to implement the contract correctly, and common mistakes to avoid.

HashSetequalshashCodeJava Collections
Illustration comparing HashSet and TreeSet in Java, showing unordered vs sorted behavior.
Java

Java HashSet vs TreeSet: Choosing the Right Set

Compare Java's HashSet and TreeSet by ordering, performance, null handling, and use cases to choose the right Set implementation.

HashSetTreeSetJava CollectionsSet Interface
Illustration comparing HashSet's unordered bucket layout with LinkedHashSet's insertion-ordered linked structure.
Java

Java HashSet vs LinkedHashSet: Ordering and Tradeoffs

Compare HashSet and LinkedHashSet in Java: ordering guarantees, internal structure, memory costs, iteration behavior, and when to choose each implementation.

HashSetLinkedHashSetJava CollectionsSet Interface
Illustration of a HashSet with scattered elements and a sorted alternative, representing unpredictable iteration order versus controlled ordering.
Java

Java HashSet Order: Unpredictable by Design

Learn why HashSet iteration order is not guaranteed and how LinkedHashSet, TreeSet, or sorting can give you predictable ordering.

HashSetJava CollectionsLinkedHashSetTreeSet
A Java HashSet with a null element highlighted, showing the special handling of null keys in the underlying HashMap.
Java

Java HashSet and null: Behavior and Pitfalls

How Java's HashSet handles null elements, including storage, performance, and common pitfalls when using null in set operations.

HashSetnull handlingJava collectionsHashMap
A Java HashSet filtering duplicate elements from a list, showing only unique values passing through the set.
Java

Java HashSet: Remove Duplicates from a List

Learn how to remove duplicates from a Java List with HashSet, including the equals and hashCode contract, ordering with LinkedHashSet, and edge cases such as nulls and mutable objects.

HashSetJava CollectionsDeduplicationLinkedHashSet
Illustration of a HashSet container accepting unique elements while rejecting a duplicate element, showing how duplicate detection works.
Java

Java HashSet Duplicates: Behavior and Detection

Java HashSet silently ignores duplicate elements. This article explains how equals() and hashCode() control duplicate detection and how to use add()'s return value to catch duplicates.

HashSetJava Collectionsequals and hashCodeDuplicate Detection
Illustration of Java HashSet iteration showing unordered traversal with a magnifying glass over a set of elements
Java

Java HashSet Iteration: Order, Removal, and Performance

Iterate a Java HashSet safely, understand why iteration order is not guaranteed, and remove elements without triggering ConcurrentModificationException.

HashSetJava CollectionsIterationIterator
Illustration of a Java HashSet with a size counter showing the element count
Java

Java HashSet Size: Using size() Correctly

Learn how to get the number of elements in a Java HashSet with size(), its constant-time behavior, and common pitfalls to avoid.

JavaHashSetCollectionssize() method
A magnifying glass over a hash set structure representing the contains method lookup in Java.
Java

Java HashSet contains: Usage and Behavior

java hashset contains: Learn how HashSet.contains works in Java, its average O(1) lookup, null handling, and the equals/hashCode contract that makes it reliable.

HashSetJava Collectionscontains methodhashCode