How to check if a String has a number in Java?

To check if a String has a number in Java, do this: string.matches(".*[\\d].*").

Here's how you do it:

// false
System.out.println("Hello World!".matches(".*[\\d].*"));

// true
System.out.println("4 You".matches(".*[\\d].*"));