Tag

Comparator

1 views collected around this technical thread.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Dec 28, 2023 · Fundamentals

Understanding Comparison Methods in Java

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
Understanding Comparison Methods in Java
Selected Java Interview Questions
Selected Java Interview Questions
Apr 18, 2022 · Fundamentals

Using Java 8 Stream sorted() for Sorting Lists, Sets, and Maps

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.

CollectionsComparatorJava
0 likes · 12 min read
Using Java 8 Stream sorted() for Sorting Lists, Sets, and Maps
IT Xianyu
IT Xianyu
Oct 10, 2020 · Fundamentals

How to Choose Between HashMap and TreeMap in Java

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.

CollectionsComparatorHashMap
0 likes · 5 min read
How to Choose Between HashMap and TreeMap in Java
Selected Java Interview Questions
Selected Java Interview Questions
Nov 19, 2019 · Fundamentals

Understanding Java Comparable and Comparator: Concepts, Differences, and Code Examples

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
Understanding Java Comparable and Comparator: Concepts, Differences, and Code Examples
Selected Java Interview Questions
Selected Java Interview Questions
Oct 10, 2019 · Fundamentals

Choosing Between HashMap and TreeMap in Java

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.

CollectionsComparatorHashMap
0 likes · 8 min read
Choosing Between HashMap and TreeMap in Java