Languages
[Edit]
EN

Java - check if string contains any numbers

0 points
Created by:
Kourtney-White
635

In this article, we would like to show you how to check if a string contains any numbers in Java.

Practical example

Edit

In this example, we use a regular expression (regex) with Pattern.matcher() to check if the strings contain any numbers.

Output:

2. Using Character.isDigit()

Edit

In this example, we create a function that loops through the string and checks if any character is a digit with Character.isDigit(char ch) method.

Practical example:

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join