1

Is it possible to get different hashcode from same string on different devices? (i got only one device so i can't test it) Or android sdk get same int value from same string on different devices? (I already have a case on .net compact fw and .net fw returns different hashcode for same string)

For example:

int hash = "Enter text".hashCode();

hash == 123445564 on Samsung S3
hash == -16644335 on HTC Desire
3
  • 1
    Codes are equal on several devices I could check. But there is absolutely no warranty that it will be in this way always. One day you app may be launched on device that has different hashCode() implementations for String. Commented Nov 15, 2012 at 13:57
  • 1
    While all devices should produce the same value (because they use the same Java implementation) you should consider using MD5 or anything that has guarantees about the outcome of a hash. hashCode() is just a random internal number that is AFAIK only guaranteed to stay the same during runtime of your app, anything beyond is unspecified. Commented Nov 15, 2012 at 14:31
  • Thanks @zapl, i'll consider to use MD5. but i think that generating md5 is more time consuming than generating hashcode. If there is no noticeable differece, i'll gonna use md5. Commented Nov 15, 2012 at 14:38

1 Answer 1

1

As long as the hash function remains the same (as far as I know it remains the same in different SDK versions) the result should be the same.

However, if you are getting the strings from strings.xml and you have localized versions of string, then you may get different hashs for the same getString(R.string.mystring)

Regards, Luis

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Luis, i mean on same string, not from android resources. I'll craft it for challenge on my question stackoverflow.com/questions/13364033/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.