generate Random Id via UUID - Java java.lang

Java examples for java.lang:String Random

Description

generate Random Id via UUID

Demo Code

//package com.java2s;

import java.util.*;

public class Main {
    public static void main(String[] argv) {
        boolean removeDashes = true;
        System.out.println(generateRandomId(removeDashes));
    }//from  w w  w. j  ava2 s.  c om

    public static String generateRandomId(boolean removeDashes) {
        String uuid = UUID.randomUUID().toString();

        if (removeDashes) {
            uuid = uuid.replace("-", "");
        }

        return uuid;
    }
}

Related Tutorials