An unique string of 16 characters. - Java java.util

Java examples for java.util:UUID

Description

An unique string of 16 characters.

Demo Code


//package com.java2s;

import java.util.UUID;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(uniqueString());
    }/*w  ww .ja  v  a 2  s  .  co m*/

    /**
     * An unique string of 16 characters.
     *
     * @return unique string
     */
    public static String uniqueString() {
        String random = UUID.randomUUID().toString();
        random = random.replaceAll("-", "");
        random = random.substring(0, 16);

        return random;
    }
}

Related Tutorials