0 votes
in JAVA by
Why CharArray() is preferred over String to store the password?

1 Answer

0 votes
by

String stays in the string pool until the garbage is collected. If we store the password into a string, it stays in the memory for a longer period, and anyone having the memory-dump can extract the password as clear text. On the other hand, Using CharArray allows us to set it to blank whenever we are done with the password. It avoids the security threat with the string by enabling us to control the memory.

Related questions

0 votes
asked Dec 16, 2020 in JAVA by SakshiSharma
0 votes
asked Mar 16, 2021 in JAVA by Robindeniel
...