LearnFrenzy
Sign in Take a free test

Strings and StringBuilder · Java Strings MCQ · Question 20

Why store passwords in char[] instead of String? Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

Why do security guidelines prefer char[] over String for passwords?

  • A char[] is faster
  • B A char array can be overwritten after use; an immutable String stays in memory until garbage collected Correct
  • C Strings cannot hold symbols
  • D char[] is encrypted
Correct Answer: Option B

That is why Console.readPassword returns char[].

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links