}
// Init variable
- String password = "";
+ StringBuilder password = new StringBuilder(length);
// Start creating it
for (int i = 0; i < length; i++) {
int pos = RANDOM_NUMBER_GENERATOR.nextInt(PASSWORD_ALPHABET.length());
// Get char at this position and add it to the final password
- password += String.valueOf(PASSWORD_ALPHABET.charAt(pos));
+ password.append(String.valueOf(PASSWORD_ALPHABET.charAt(pos)));
}
// Should have the wanted length
assert (password.length() == length) : "Password length " + password.length() + " doesn't match requested: " + length;
// Return it
- return password;
+ return password.toString();
}
/**