2

I'm basically trying to build a random password generator in Java. I'm trying to build it using a char array, basically:

char[] password = new char[8]

I want to be able to include "special" characters in this array (such as @, $, *, etc). Can these characters be placed in a char array, and if so, how?

3
  • There is no such thing as Char type in Java. There is char or Character. Commented Jun 21, 2015 at 11:59
  • Also yes, characters are written with ' like 'a' so you can place them in array just like you normally place any element. Commented Jun 21, 2015 at 12:00
  • If you are generating passwords, then use SecureRandom instead of simple Random. It does make a difference. Commented Jun 21, 2015 at 12:31

1 Answer 1

3

Put characters in array inline

char[] password = {'@', '$', '*'};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.