Create hash from string and int

前端 未结 6 1750
离开以前
离开以前 2021-02-07 20:14

I remember eclipse and idea have this template to automatically create an object\'s hashCode based on its attributes.

One of the strategies if a number and a string is u

6条回答
  •  囚心锁ツ
    2021-02-07 20:39

    Use the Apache Commons HashcodeBuilder:

    public int hashCode() {
        new HashCodeBuilder(17, 37).
               append(myString).
               append(myInt);
    }
    

    Link here: http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/builder/HashCodeBuilder.html

    And here:

    http://www.koders.com/java/fidCE4E86F23847AE93909CE105394B668DDB0F491A.aspx

提交回复
热议问题