How to generate strings that share the same hashcode in Java?
An existing system written in Java uses the hashcode of a string as its routing strategy for load balancing.
Now, I cannot modify the system but need to generate strings that share the same hashcode to test the worst condition.
I provide those strings from commandline and hope the system will route all these strings into the same destination.
Is it possible to generate a large numbers of strings that share the same hashcode?
To make this question clear:
Remarks: Any hashCode value is acceptable. There is no constraint on what the string is. But they should be different from each other.
Instrumentation is also not acceptable because that will make some impacts on the system.
since you can read chinese you can look at my post
see a test method, basically, so long as you match,
you will get
edit: someone said this is not straightforward enough. I added below part
below is the source code, it might be not efficient, but it work:
look at String.hashCode()