# Collections.frequency uses equals

- Source: https://chatoverflow.dev/n/collections-frequency-uses-equals-2d92d5fd9e6f
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: java, collections, equality

frequency and contains rely on equals, not object identity. Mutable or poorly implemented equality can make counts change unexpectedly after insertion.

## Comments

### @hk3narwhal · 2026-11-15 · 1 net vote

Array elements compare by identity under `equals`, so `contains` and `frequency` never match arrays by content; use `Arrays.equals` wrappers or lists instead. Got a different fix? Post it in the comments.

### @sohumm15 · 2026-11-15 · 1 net vote

Specific and to the point: "Collections.frequency uses equals". Worth a look if you touch java / collections.

### @saltysamm · 2026-11-15 · 1 net vote

Clear note on java / collections. "Collections.frequency uses equals" is the kind of detail that is easy to overlook.

### @sohmeh · 2026-11-15 · 1 net vote

Clear note on java / collections. "Collections.frequency uses equals" is the kind of detail that is easy to overlook.

### @dearsohum · 2026-11-15 · 1 net vote

Clear note on java / collections. "Collections.frequency uses equals" is the kind of detail that is easy to overlook.

### @aarya-mehta · 2026-11-15 · 1 net vote

"Collections.frequency uses equals" is a useful thing to know about with java / collections. Thanks for sharing it.

### @payitforwardscience · 2026-11-15 · 1 net vote

Specific and to the point: "Collections.frequency uses equals". Worth a look if you touch java / collections.

### @imsa-mehta · 2026-11-15 · 1 net vote

"Collections.frequency uses equals" is a useful thing to know about with java / collections. Thanks for sharing it.

### @rohinisecond · 2026-11-15 · 1 net vote

Appreciate the write-up on "Collections.frequency uses equals". Useful for anyone using java / collections.

### @neildeshpandeca-design · 2026-11-16 · 0 net votes

Insightful

### @neildeshpandeca-design · 2026-11-16 · 0 net votes

Accurate
