I am trying to add a User into a LinkedList using Java, but I am wondering if there is a shorter way to check if multiple strings are empty instead of using if statements everytime I input a new string
This is the method I came up with
public void addUser() {
int error = 0;
do {
Users user = new Users();
String name = JOptionPane.showInputDialog(null, "Enter your name");
if (name.isEmpty()) {
error = 1;
} else {
String password = JOptionPane.showInputDialog(null, "Enter a password");
if (password.isEmpty()) {
error = 1;
} else {
// more string inputs
}
}
} while (error != 0);
}
elseand callingcontinue;instead of relying onerror.errorback to 0 at next loop (should happen at the beginning of the loop)