How to Generate Unique ID in Java (Integer)?

后端 未结 9 1521
生来不讨喜
生来不讨喜 2020-12-06 04:11

How to generate unique ID that is integer in java that not guess next number?

9条回答
  •  醉话见心
    2020-12-06 04:52

    int uniqueId = 0;
    
    int getUniqueId()
    {
        return uniqueId++;
    }
    

    Add synchronized if you want it to be thread safe.

提交回复
热议问题