Languages
[Edit]
EN

Java - check if string only contains letters

0 points
Created by:
halfera
411

In this article, we would like to show you how to check if the string only contains letters in Java.

1. Using regex

Edit

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

Output:

2. Using Character.isLetter()

Edit

In this example, we create a function that loops through the string and checks if each character is a letter with Character.isLetter(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