Skip to content
Advertisement

How do I check if a string contains a list of characters?

How do I check if a list of characters are in a String, for example “ABCDEFGH” how do I check if any one of those is in a string.

Advertisement

Answer

use regular expression in java to check using str.matches(regex_here) regex in java

for example:

    if("asdhAkldffl".matches(".*[ABCDEFGH].*"))
    {
        System.out.println("yes");
    }
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement