Shef's answer doesn't compile for me. It looks like he's using RegEx in String.contains()
. If you want to use RegEx use this:
String strWithNumber = "This string has a 1 number";
String strWithoutNumber = "This string has a number";
System.out.println(strWithNumber.matches(".*\\d.*"));
System.out.println(strWithoutNumber.matches(".*\\d.*"));