Create hash from string and int

前端 未结 6 1772
离开以前
离开以前 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 20:38

    Or, if you don't want to add another library, do something like the following:

    public int hashCode() {
        StringBuilder builder = new StringBuilder();
        builder.append(myString);
        builder.append(myInteger);
        return builder.toString().hashCode();
    }
    

提交回复
热议问题