Java UUID Create generateId()

Here you can find the source of generateId()

Description

Generates and returns unique identifier.

License

Open Source License

Return

unique identifier

Declaration

public static String generateId() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Zend Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * // ww w  .  j ava2  s .co  m
 * Contributors:
 *     Zend Technologies - initial API and implementation
 *******************************************************************************/

import java.util.UUID;

public class Main {
    /**
     * Generates and returns unique identifier with provided prefix.
     * 
     * @param prefix
     * @return unique identifier with provided prefix
     */
    public static String generateId(String prefix) {
        return prefix + '-' + UUID.randomUUID().toString();
    }

    /**
     * Generates and returns unique identifier.
     * 
     * @return unique identifier
     */
    public static String generateId() {
        return UUID.randomUUID().toString();
    }
}

Related

  1. generateFileName(String path)
  2. generateGUID()
  3. generateGUID()
  4. generateId()
  5. generateID()
  6. generateRandomMap(int count)
  7. generateRandomName()
  8. GenerateRandomSlug()
  9. generateRandomString(int length)