Home  >  Article  >  Java  >  UUID generation in Java

UUID generation in Java

黄舟
黄舟Original
2017-01-17 15:06:191593browse

happy smile

I said: "You are a pig." You said: "I am a pig!" From now on, I will call you a pig. Finally one day, you couldn't help but yelled at me in front of everyone: "I'm not a pig!"

Ask a question

How to use java's UUID class to generate a 32-bit UUID ???

Solve the problem

The following are 2 UUID generation methods. In the real project, I used the first method:

[code]import java.util.UUID;

/**
 * Created by Ay on 2016/4/18.
 */
public class JavaUUIDTest {

    public static void main(String[] args) {

        //未加工的UUID
        String preUuid = UUID.randomUUID().toString();
        System.out.println(preUuid);

        //第一种方法生成UUID,去掉“-”符号
        System.out.println(UUID.randomUUID().toString().replace("-", ""));

        //未加工的UUID
        String preUuid2 = UUID.randomUUID().toString();
        System.out.println(preUuid2);
        //第二种生成UUID的方法,去掉“-”符号
        String changUuid = preUuid2.substring(0,8)+preUuid2.substring(9,13)+preUuid2.
        substring(14,18)+preUuid2.substring(19,23)+preUuid2.substring(24);

        System.out.println(changUuid);
    }
}

Result:

UUID generation in Java

Reading Insights

Do a good job in every job in your hands. If you think you deserve a better salary and job, you must base it on being able to do your current job well. If you don't accumulate steps, you can't reach a thousand miles. Do every little thing well, even if it is a broken company. Believe me, if you do a perfunctory job because the company/leader/colleagues are not good, only one person will be hurt, and that is you.

less talking, more working. In an era of universal education and a flood of information, everyone has the right to make irresponsible remarks on everything. Especially when I was young, my blood was boiling, and there were so many things that I couldn't understand. How could I not say a few words? Believe me, you can only truly change the world by doing it rather than saying it.

A life that has not experienced pain and failure is an incomplete life. Pain makes our life experience richer, and failure is an indispensable accompaniment of success. When pain and failure come, you must have Defeat them with full courage and confidence.

The above is the content generated by Java's UUID. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn