UUID to unique integer id?

前端 未结 6 750
悲哀的现实
悲哀的现实 2021-01-01 08:37

I was wondering what the easiest way to convert a UUID to a unique integer would be? I have tried using the hash code but people tell me that it is not going to always be un

6条回答
  •  天命终不由人
    2021-01-01 09:10

    You are going to have a problem since the UUID is 128 bits and the int is only 32bit. You'll either have to accept the risk of collisions and try to fudge it to a smaller space (hashCode is probably a good way to do that) or find an alternative (use the UUID directly, map to a BigInteger - difficult to tell without knowing why)

提交回复
热议问题