0
In the following code snippet why is char[] is used, when we can use String?
public void passgen(){ int length = 10; System.out.println("Your Password is...."); char[] pass = generatePswd(length); a = new String(pass); System.out.println(a); } char[] generatePswd(int len)
2 Respuestas
+ 5
I think it's because it's a password generator, it is design to generate the password character by character, therefore it used char array instead of String, and later convert the char array to String to display the result password to the user
+ 4
Char means a single character,where as a string can store multiple characters.And you are using char array.
A string :- Hello
char array :- H,e,l,l,o
This is done to treat each character of string individually.