Java Cup
Inside Java

News and views from members of the Java team at Oracle

Write Efficient Bug-free and Simple Comparators in Java - JEP Café #17

How to write good, bug free and correct comparators.

Comparator instances are elements used daily in all Java applications. They are fairly easy to write, but must also follow several subtle rules. This JEP Café explains all of them: how to leverage the factory methods from the Comparator interface, and from the wrapper classes of primitive types. We also cover even more subtle and unexpected bugs you may come across with HashSet and HashMap if your comparators are not consistent.

Show Notes

Further reading and viewing:

JDK releases:

Additional Resources

JEP Café explores Java features and JDK Enhancement Proposals through tutorials and practical examples. Watch all episodes in the YouTube playlist. For more Java news, subscribe to our RSS feed and follow @Java on X.

Contact us.