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

  • Home
  • SEARCH
  • 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 8684583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:20:39+00:00 2026-06-12T22:20:39+00:00

I have a program for my Java class where I want to use hashSets

  • 0

I have a program for my Java class where I want to use hashSets to compare a directory of text documents. Essentially, my plan is to create a hashSet of strings for each paper, and then add two of the papers hashSets together into one hashSet and find the number of same 6-word sequences.

My question is, do I have to manually check for, and handle, collisions, or does Java do that for me?

  • 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-12T22:20:40+00:00Added an answer on June 12, 2026 at 10:20 pm

    Java Hash Maps/Sets Automatically handle Hash collisions, this is why it is important to override both the equals and the hashCode methods. As both of them are utilised by Sets to differentiate duplicate or unique entries.

    It is also important to note that these hash collisions hava a performance impace since multiple objects are referenced by the same Hash.

    public class MyObject {
    private String name;
    
    //getter and setters
    
    
    public int hashCode() {
       int hashCode = //Do some object specifc stuff to gen hashCode
       return int;
    }
    
    public boolean equals(Object obj) {
       if(this==obj) return true;
       if(obj instanceOf MyObject) {
           if(this.name.equals((MyObject)obj.getName())) {
               return true;
           }
       return false;
    }
    }
    }
    

    Note: Standard Java Objects such as String have already implemented hashCode and equals so you only have to do that for your own kind of Data Objects.

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

Sidebar

Related Questions

i want to use the Java program in JSP. i have created java program
i have a really basic java program just one .java/.class file (.java uncompiled .class
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have made a front end for a program which test java (foo.class) binary
Currently I am writing a program for an introductory Java class. I have two
I have a dummy Java Program, which I want to write in Clojure. It
I have a Java program which its main method (in the main class) expects
I have a Java threadpool created via Executors.newFixedThreadPool() that I want to use daemon
I have a Java program that loads thirdparty class files (classes I did not
So in my java class we have a homework assignment to use System.currentTimeMillis to

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.