---
title: "Discussion on \"Why (a, b) -> a - b Is a Bug in Java Comparators\" | Hashnode"
description: "Discussion on \"Why (a, b) -> a - b Is a Bug in Java Comparators\". a - b comparators overflow and silently mis-sort lists and heaps. Real Java output, the long/double cast traps, and the one-line fixes."
url: "https://hashnode.com/posts/java-comparator-a-minus-b-overflow-bug/6ae06f18fe43b5b6b39e8cc2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why (a, b) -> a - b Is a Bug in Java Comparators](https://gowthammuthuvel.hashnode.dev/java-comparator-a-minus-b-overflow-bug?utm_source=hashnode&utm_medium=feed)

a - b comparators overflow and silently mis-sort lists and heaps. Real Java output, the long/double cast traps, and the one-line fixes.

Oct 27 · 8 min read · gowthammuthuvel.hashnode.dev  
Updated 5d ago  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#dsa](https://hashnode.com/tag/dsa)
-   [#interview-preparation](https://hashnode.com/tag/interview-preparation)
-   [#leetcode](https://hashnode.com/tag/leetcode)
-   [#collections](https://hashnode.com/tag/collections)

## Written by

[Gowtham Muthuvel](https://hashnode.com/@GowthamMuthuvel)

@GowthamMuthuvel

  
[View profile](https://hashnode.com/@GowthamMuthuvel)

Full-stack developer | Java, Spring Boot, React | Senior Backend Developer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
