Why does JPasswordField.getPassword() create a String with the password in it?

前端 未结 7 2031
长发绾君心
长发绾君心 2020-11-28 10:52

Swing\'s JPasswordField has the getPassword() method that returns a char array. My understanding of this is that the array can be zeroed immediately after use so that you do

7条回答
  •  执笔经年
    2020-11-28 11:36

    This works for me and helps you to build a Stringified password:

    String passText = new String(passField.getPassword());
    

提交回复
热议问题