I’m trying to create a method which checks if the Login (username and password) has a minimum of 6 charakters.
To realize that I created this method public void checkLoginData(final String username, final String password). In that method, I create to booleans (user and pass), with those I can create 4 different boolean-chains:
- user: true pass: true
- user: false pass: true
- user: false pass: false
- user: true pass: false
Now I’d like to do a switch/case request for each of them, but I don’t get how to realize that…
If you ask why I need the switch, I just think I need it, because I’d like to do for every of those 4 boolean-chains, that it does/show something diffrent. Also I’d like to do this in a sexy-java-way not with tousands of diffrent ‘ifs’ :P, Please help!
Here’s the code of the method:
public void checkLoginData(final String username, final String password){
boolean user, pass;
if (username.length() < 6){
user = false;
}else {
user = true;
}
if (password.length() < 6){
pass = false;
}else {
pass = true;
}
boolean[] logindaten = {user, pass};
}
Thx for the help in Advance!
Best Regards safari
You can’t switch over
boolean[], only over integral types. To convert the booleans to an int, you could use a bit mask for the 2 booleans, like for example this: