- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a string contains only alphabets in Java using Lambda expression
Let’s say our string is −
String str = "Amit123";
Now, using allMatch() method, get the boolean result whether the string has only alphabets or now −
boolean result = str.chars().allMatch(Character::isLetter);
Following is an example to check if a string contains only alphabets using Lambda Expressions −
Example
class Main { public static void main(String[] args) { String str = "Amit123"; boolean result = str.chars().allMatch(Character::isLetter); System.out.println("String contains only alphabets? = "+result); } }
Output
Let us see another example with a different input −
String contains only alphabets? = false
Example
class Main { public static void main(String[] args) { String str = "Jacob"; boolean result = str.chars().allMatch(Character::isLetter); System.out.println("String contains only alphabets? = "+result); } }
Output
String contains only alphabets? = true
- Related Articles
- Check if a string contains only alphabets in Java using Regex
- Check if a string contains only alphabets in Java using ASCII values
- Java Regular expression to check if a string contains alphabet
- Check if the String contains only unicode letters in Java
- Check if a string contains a number using Java.
- How to check if a character column only contains alphabets in R data frame?
- Is it possible to check if a String only contains ASCII in java?
- How to reverse a string using lambda expression in Java?
- Java Program to check if the String contains only certain characters
- Check if the String contains only unicode letters and space in Java
- Check if the String contains only unicode letters or digits in Java
- How to check if a Python string contains only digits?
- How to check if a string contains only decimal characters?
- Check if the String contains only unicode letters, digits or space in Java
- Python Program to check if String contains only Defined Characters using Regex

Advertisements