Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.UUID;

public class Main {
    /**
     * This method generates the unique GUID string of the length specified in passed
     * parameter.
     *
     * @param notAllowedChars Regular expression to replace any invalid characters
     * @param length Length to restrict the output to
     * @return the unique string
     */
    public static String generateGUID(String notAllowedChars, int length) {
        String guid = UUID.randomUUID().toString();
        // Remove all the hypen's (-) from the page token
        guid = guid.replaceAll(notAllowedChars, "");
        // make it a 32-bit token
        guid = guid.substring(0, length);
        return guid;
    }
}