Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
