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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:22+00:00 2026-05-27T11:39:22+00:00

I have a class like this Class A{ private String string1; private String string2;

  • 0

I have a class like this

Class A{

  private String string1;
  private String string2;
  ..
  ..

  private String string19;

}

Some of the strings may be empty.

I want to get an hash/identifier (string or number) for the instances of this class.
I can use hashCode but i don’t know if i can get some collision, i have a lot of instances of this class (about 4-5 million).

I need a fast way to get this hash.

Thanks for the help.

  • 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-27T11:39:23+00:00Added an answer on May 27, 2026 at 11:39 am

    You could write a custom hashCode method that uses a slightly altered version of the hashCode algorithm in the String class. From the Oracle documentation, the String hashCode is computed as follows:

     s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
    

    You could implement a modified version where you compute n over all the String objects in your class. This way you are not wasting space and time creating a concatenated String to do the same. In some circumstances this might be fine, but with 4-5 million objects, you probably want to avoid that much churn.

    Source: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#hashCode%28%29

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

Sidebar

Related Questions

I have a class which holds strings. I declared them like this: private String
If I have a simple class setup like this: class MyClass { private string
I have a class like this: private class MyClass { [DisplayName(Foo/Bar)] public string FooBar
I have a class like this: public class SomeClass { private const string sessionKey
I have a class like this public SomeClass { private List<string> _strings = new
I have class like this: public class Class1 { private String result; private String
lets say I have a class like this: public class MyClass { private String
Let's say I have a class like this: public class Person { private String
I have a class like this: class A { private: B* ptr; } But
I have a class like this public class foo { private void getThread() {

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.