How to generate strings that share the same hashcode in Java?

前端 未结 6 1267
余生分开走
余生分开走 2020-12-28 10:09

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 ne

6条回答
  •  时光说笑
    2020-12-28 10:24

    String s = "Some String"
    for (int i = 0; i < SOME_VERY_BIG_NUMBER; ++i) {
        String copy = new String(s);
    
        // Do something with copy.
    }
    

    Will this work for you? It just creates a lot of copies of the same String literal that you can then use in your testing.

提交回复
热议问题