Java Password Generate generateStrings(int count, int length)

Here you can find the source of generateStrings(int count, int length)

Description

Generates an array of strings.

License

Apache License

Parameter

Parameter Description
count number of String in the array
length the length of each individual string

Return

the created array of Strings.

Declaration

public static String[] generateStrings(int count, int length) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    private final static String alphabet = "abcdefghijklmnopqrstuvwxyz1234567890";
    private final static Random random = new Random();

    /**/* w w w . j  av a  2 s.c om*/
     * Generates an array of strings.
     *
     * @param count number of String in the array
     * @param length the length of each individual string
     * @return the created array of Strings.
     */
    public static String[] generateStrings(int count, int length) {
        String[] keys = new String[count];
        for (int k = 0; k < keys.length; k++) {
            keys[k] = generateString(length);
        }
        return keys;
    }

    public static String generateString(int length) {
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < length; k++) {
            char c = alphabet.charAt(random.nextInt(alphabet.length()));
            sb.append(c);
        }

        return sb.toString();
    }
}

Related

  1. generateString(int length)
  2. GenerateString(int Length)
  3. generateString(int maxlength)
  4. generateString(String alphabet, int length)
  5. generateString(String charSet, int len)
  6. generateStringsEntries(int cnt)
  7. getDummyPassword()