Java Random String getRandomString(final int len)

Here you can find the source of getRandomString(final int len)

Description

Get random string

License

Open Source License

Parameter

Parameter Description
len a parameter

Declaration

public static synchronized final String getRandomString(final int len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    /**//  w  w  w.  j av a 2  s .c  om
     * Get random string
     * 
     * @param len
     * @return
     */
    public static synchronized final String getRandomString(final int len) {
        final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        final Random rnd = new Random();
        final StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            sb.append(AB.charAt(rnd.nextInt(AB.length())));
        }
        return sb.toString();
    }
}

Related

  1. getRandomString()
  2. getRandomString()
  3. getRandomString()
  4. getRandomString()
  5. getRandomString(final int len)
  6. getRandomString(final int length)
  7. getRandomString(final int size)
  8. getRandomString(final int size)
  9. getRandomString(int cantidad, boolean mayusculas, boolean minusculas, boolean numeros, boolean simbolos, boolean repetir)