Using a loop -
public static boolean containsDigit(final String aString)
{
if (aString != null && !aString.isEmpty())
{
for (char c : aString.toCharArray())
{
if (Character.isDigit(c))
{
return true;
}
}
}
return false;
}
Using a stream -
public static boolean containsDigit(final String aString)
{
return aString != null && !aString.isEmpty() &&
aString.chars().anyMatch(Character::isDigit);
}