I am working on a program that lets a user input an alphanumeric key, and checks if it is a valid key against some criteria, one of these is whether or not the key contains an uppercase. TThis is what I have tried so far:
else if (key.contains("QWERTYUIOPASDFGHJKLZXCVBNM")){
UI.println("Invalid, key contains a space, illegal character");
}
This only detects the capital letters if they are written in this order. is there a command such as key.contains i should be using?
With streams, you can to the following.
key.chars().anyMatch(Character::isUpperCase)
This is much lighter than regexes in terms of resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With