我觉得这是检查的时间越长,繁琐和低效的方式:如何有效检查两个字符串是相同的,它们的非空
- 该密码字段不为空
- 那这两个密码相匹配
- 两个密码是不一样的
private void checkPasswordSame() {
String first = password1.getText();
String second = password2.getText();
if (first.equals("")) {
System.out.println("Password can't be empty");
if ("".equals(second)) {
System.out.println("Second password is empty");
}
} else if (first.equals(second)) {
System.out.println("Passwords same");
} else {
System.out.println("Passwords not the same");
}
}
有没有办法以较少的行数来做到这一点?
为什么所有的等于(“”)在这个问题和答案? isEmpty()方法有什么问题?有没有我不知道的一些魔术迷你优化技巧? – Gimby 2014-09-05 07:58:25