Java UUID Create generateUUID()

Here you can find the source of generateUUID()

Description

generate UUID

License

Open Source License

Declaration

public static UUID generateUUID() 

Method Source Code

//package com.java2s;
/*//w w w.j a v a 2  s.  com
 * Copyright (C) 2013 DASISH
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.util.UUID;

import java.util.Random;

public class Main {
    final static String hexa = "ABCDEabcde";
    final static int hexan = hexa.length();

    public static UUID generateUUID() {
        UUID result = UUID.randomUUID();
        char[] chars = result.toString().toCharArray();
        if (chars[0] >= 'a' && chars[0] <= 'z') {
            return result;
        } else {
            Random r = new Random();
            chars[0] = hexa.charAt(r.nextInt(hexan));
            result = UUID.fromString(new String(chars));
            return result;
        }
    }
}

Related

  1. generateUUID()
  2. generateUUID()
  3. generateUUID()
  4. generateUUID()
  5. generateUuid()
  6. generateUUID()
  7. generateUUID()
  8. generateUUID()
  9. generateUUID()