Browse by Topic

Popular

Latest

Latest Java Posts

Illustration of a Java HashMap being initialized with capacity and entries, showing a bucket array and key-value pairs.
Java

Java HashMap Initialization: Syntax and Pitfalls

Learn how to initialize a HashMap in Java, including constructors, capacity and load factor, copy constructors, Map.of, and common pitfalls.

HashMapJava CollectionsInitial CapacityMap.of
Illustration of a Java HashMap declaration showing key-value pairs mapped into an array of buckets
Java

Java HashMap Declaration: Syntax and Common Pitfalls

Learn correct HashMap declaration syntax in Java: generics, the diamond operator, initial capacity, and when to choose immutable Map.of instead.

HashMapJava CollectionsGenericsMap Interface
Illustration of a Java HashMap with key-value pairs and hash buckets
Java

Java HashMap: How It Works and When to Use It

Understand Java HashMap's internal structure, performance characteristics, and common pitfalls to write efficient, predictable code.

javahashmapcollectionsperformance
Diagram contrasting Java Set and List collection behavior with ordering and duplicate handling
Java

Java Set vs List: Choosing the Right Collection

Compare Java's Set and List interfaces: ordering, duplicates, access patterns, implementation tradeoffs, and when each collection fits your code.

Java CollectionsHashSetArrayListData Structures
A locked set icon with Java code elements, representing an immutable set in Java
Java

Creating and Using Java Immutable Sets

Learn how to create and use Java immutable sets with Set.of, understand their null and ordering behavior, and avoid common pitfalls with unmodifiable views.

immutable collectionsSet.ofJava collectionsunmodifiable set
Illustration of a Java Set collection showing unique elements with a focus on order and uniqueness
Java

Java Set.of(): Creating and Using Sets

Learn how to create, populate, and iterate over a Set in Java, including the differences between HashSet, TreeSet, and LinkedHashSet.

JavaSet interfaceHashSetTreeSet
Diagram comparing HashSet, LinkedHashSet, and TreeSet ordering and performance for Java Set methods.
Java

Java Set Methods: Usage and Behavior

Learn how Java Set methods work, including add, remove, contains, and iteration, with practical examples for HashSet, LinkedHashSet, and TreeSet.

Java SetHashSetLinkedHashSetTreeSet
Illustration of the Java Set interface showing a HashSet, TreeSet, and LinkedHashSet with unique elements and ordering differences.
Java

Java Set Interface: Implementation Choices and Behavior

Understand the Java Set interface contract and how HashSet, LinkedHashSet, TreeSet, and EnumSet differ in ordering, null handling, and concurrency behavior.

Set interfaceHashSetTreeSetJava collections
A TreeSet diagram showing null elements being rejected by default and allowed with a custom comparator.
Java

Java TreeSet Null Handling: Allow or Reject Nulls

A TreeSet throws NullPointerException when adding null without a comparator that handles it. This article explains why, and how to allow nulls with Comparator.nullsFirst or nullsLast.

TreeSetNullPointerExceptionComparatorJava Collections
Illustration of a TreeSet with ceiling and floor pointers finding nearest values in a sorted set
Java

Java TreeSet ceiling and floor methods

java treeset ceiling floor: Learn how to use TreeSet's ceiling and floor methods to find nearest elements, handle edge cases, and understand their performance.

TreeSetJava CollectionsSortedSetNavigableSet