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 6535055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:19:36+00:00 2026-05-25T10:19:36+00:00

Java defines a Set interface where contains() is defined as following: Returns true if

  • 0

Java defines a Set interface where contains() is defined as following:

Returns true if this set contains the specified element. More
formally, returns true if and only if this set contains an element e
such that (o==null ? e==null : o.equals(e)).

The Collection interface defines contains() as following:

Returns true if this collection contains the specified element. More
formally, returns true if and only if this collection contains at
least one element e such that (o==null ? e==null : o.equals(e)).

I need a Java ‘instance set’ where contains() is based on == and not equals(). In other words, a set of hard instances where two different objects A and B where A.equals(B) could coexist in this same set, since A!=B.

Is such an ‘instance set’ delivered in Java or in some public library? I can’t find anything, but may be someone knows better on SO. If not, I’ll implement it. Thanks.

  • 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-05-25T10:19:36+00:00Added an answer on May 25, 2026 at 10:19 am

    There is no direct “instance set” in the JRE.

    But there is an IdentityHashMap, which implements a “instance map” according to your terminology.

    And there is a method called Collections.newSetFromMap() which can create a Set from an arbitrary Map implementation.

    So you can easily build your own instance set like this:

    Set<MyType> instanceSet = Collections.newSetFromMap(new IdentityHashMap<MyType,Boolean>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the following Unit-Test: [TestMethod] //@Test for the Java crowd public void
Java doc TreeSet contains enigmatic assertion: The behavior of a TreeSet is well-defined even
The Java Collections interfaces (for example, List or Set ) define the contains method
In java.util.Calendar , January is defined as month 0, not month 1. Is there
I'm working on a java program, and I have several vectors defined and filled
(Java question) If I reference a field in an inner class, does this cause
Java SE 6 (64 bit only) is now on OS X and that is
I am creating a set of widgets in Java that decodes and displays messages
I am currently working with JNI (Java Native Interface) to send data between Java
Does anyone know if it possible to define the equivalent of a java custom

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.