且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

字符串替换不起作用我认为应该

更新时间:2023-11-05 14:23:34

始终重新分配。

password = password.replace("Password: ", " ");

字符串在Java中是不可变的,这意味着您无法修改它的现有实例。通过重新分配它,您将捕获字符串的新值到现有变量中。

Strings are immutable in Java, meaning you can't modify an existing instance of it. By re-assigning it, you'll be capturing the new value of the string into an existing variable.