File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Create String Object with Object.hashCode() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create String Object with Object.hashCode()" Watch "Create String Object with Object.hashCode()" New topic
Author

Create String Object with Object.hashCode()

David Cuesta
Greenhorn

Joined: Nov 07, 2001
Posts: 25
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,
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
David Cuesta
Greenhorn

Joined: Nov 07, 2001
Posts: 25
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create String Object with Object.hashCode()