Tagged articles
Comparator
11 articles · Page 1 of 1
A hands-on guide demonstrating how Java Stream API reduces a real-world reporting task from 78 lines to 17, covering deduplication strategies, multi-level sorting pitfalls, grouping with downstream collectors, and one-pass statistics using IntSummaryStatistics.
CollectorsComparatorIntSummaryStatistics
0 likes · 23 min read

The article explains how the Strategy design pattern solves the maintenance nightmare of tangled if‑else or switch statements by extracting each algorithm into its own strategy class, detailing the roles, selection mechanisms, Java examples, and when the pattern is appropriate.
ComparatorJavaOpen/Closed Principle
0 likes · 14 min read

This article explains Java's functional interfaces—Predicate, Function, Consumer, Supplier, and Comparator—showing their method signatures, how to compose them, custom interface creation, common pitfalls, and concise code examples for everyday use.
ComparatorConsumerFunction
0 likes · 10 min read

This article explains the hidden pitfalls of using Java's Comparable for sorting, demonstrates how null handling and fragmented comparison logic can cause bugs, and shows how the flexible Comparator API together with chainable methods provides safer, more performant dynamic sorting solutions for constantly changing business requirements.
ComparableComparatorJava
0 likes · 7 min read

This article explains various comparison methods in Java, including equality operators, the equals() method, Comparator and Comparable interfaces, and provides code examples for primitive, object, string comparisons, as well as custom sorting logic, highlighting their roles in sorting, searching, and data handling.
ComparableComparatorJava
0 likes · 14 min read

This tutorial demonstrates how to use Java 8 Stream's sorted() method to perform natural ordering, custom Comparator sorting, and reverse ordering on List, Set, and Map collections, including examples with lambda expressions and custom objects.
ComparatorJavaStream
0 likes · 12 min read

This article explains multiple ways to eliminate duplicate strings and objects from Java List collections, covering classic Set‑based methods, Java 8 Stream distinct operations, custom equals/hashCode implementations, and field‑based deduplication using comparators and generic predicates.
ComparatorJavaList
0 likes · 6 min read

HashMap and TreeMap serve different purposes in Java: HashMap offers fast, unordered access using hash codes, while TreeMap maintains keys in sorted order via a red‑black tree, and the article explains their implementations, performance trade‑offs, and how to customize TreeMap ordering with comparators.
ComparatorHashMapJava
0 likes · 5 min read

This article explains Java's two comparison mechanisms—Comparable and Comparator—detailing their purposes, implementation differences, and providing clear code examples that demonstrate how each works and when to use them in sorting custom objects.
Code ExampleComparableComparator
0 likes · 6 min read

This article explains the differences between Java's HashMap and TreeMap, covering their underlying implementations, performance characteristics, ordering behavior, and how to use a custom comparator to achieve descending order, helping developers choose the appropriate map based on ordering and efficiency needs.
ComparatorHashMapJava
0 likes · 8 min read

This article explains Java's Comparator interface, its compare method, lambda definitions, and how to use it with Collections.sort, List.sort, Arrays.sort, Stream.sorted, as well as with SortedSet and SortedMap structures, covering static and default methods like reversed, nullsFirst, thenComparing, and more.
ComparatorJavaTreeMap
0 likes · 31 min read
