Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:08:26+00:00 2026-06-15T10:08:26+00:00

I am exploring the various methods, operations and prerequisites of the most common Java

  • 0

I am exploring the various methods, operations and prerequisites of the most common Java collections and I am a little bit confused. I would be very grateful if somebody could clarify the following topics:

1) Is the implementation of the methods equals and hashCode absolutely required, in order for a TreeSet and a TreeMap to work properly, as it is in HashMap? What are the potential implications of not implementing the previous methods? I am making currently use of a TreeMap and a TreeSet (of custom class Objects) and they work fine so far, just by implementing Comparable and its method compareTo, ommiting equals and hashCode.

2) When impelmenting in a class equals, hashCode or even the interface Comparable, is it sufficient for all derived classes to work properly in collections according those methods without new definition and implementantion? I have the impression that the former is right, since the given methods belong to the derived classe as well. What is finally true?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:08:27+00:00Added an answer on June 15, 2026 at 10:08 am

    Is the implementation of the methods equals and hashCode absolutely required, in order for a TreeSet and a TreeMap to work properly, as it is in HashMap?

    no.

    What are the potential implications of not implementing the previous methods?

    none.

    When impelmenting in a class equals, hashCode or even the interface Comparable, is it sufficient for all derived classes to work properly in collections according those methods without new definition and implementantion?

    Yes, making “work properly” isn’t as simple as it sounds. Generally you want the keys or element to all the same type. It rarely a good idea to mix their types.

    For TreeMap and TreeSet you only need to implement Comparable + compareTo OR a Comparator + compare.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been exploring patterns in various MV* frameworks out there and today noticed
I've been exploring methods for full-width background images combined with type. I found this
While exploring various ways of computing factorials in Clojure, I came up with the
I am exploring various architectures in cluster computing. Some of the popular ones are:
I saw this article recently while exploring various ways to work with images at
What various methods and technologies have you used to successfully address scalability and performance
I am currently exploring various code coverage tools for use in project and short
I'm doing some exploring of various languages I hadn't used before, using a simple
Wikipedia provides information about one of the most common scenarios for exploiting a reflected
We're exporting our analytics reports in various formats, among them CSV. For some clients

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.