• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create String Object with Object.hashCode()

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Somebody knows how can i create a String if i have his hashCode?, the api says that hashCode method of String class uses the folowing code:
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
but, i havn't got time to make experiments,
Thanks,
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don' know that you can work backwards like this. You could convert the decimal hashcode to a base 31 number and then interpret the string, but you can only reconstruct the original string using this method if your original string used only ASCII values 0-30, all of which are NPCs/whitespace. Not very useful.
 
David Cuesta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i'm trying to use hashCode as parameter in an URL, but i think that the best way is to convert it in a hexadecimal String, hidding the parameters
Example:
Hello -> A2B2 ...

Thanks for all
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic