Given a String, the task is to check whether a string contains only alphabets or not.
Input : GeeksforGeeks Output : True Input : Geeks4Geeks Output : False Input : null Output : False
The idea is to use isLetter() method of Character class.
- Get the string
- Match the string:
- Check if the string is empty or not. If empty, return false
- Check if the string is null or not. If null, return false.
- If the string is neither empty nor null,
then check using Lambda Expression Character::isLetter().
- Return true if matched
Program: Checking if String contains only Alphabets.
Test Case 1: Input: GeeksforGeeks Output: true Test Case 2: Input: Geeks4Geeks Output: false Test Case 3: Input: null Output: false Test Case 4: Input: Output: false
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Check if a string contains only alphabets in Java using ASCII values
- Check if a string contains only alphabets in Java using Regex
- Check if a string contains only alphabets in Java
- Java Lambda Expression with Collections
- Map function and Lambda expression in Python to replace characters
- Difference between Anonymous Inner Class and Lambda Expression
- Sub-string that contains all lowercase alphabets after performing the given operation
- Program to check if a String in Java contains only whitespaces
- How to check if string contains only digits in Java
- Check if expression contains redundant bracket or not | Set 2
- Lambda Expressions in Java 8
- Arithmetic Expression Having Only + and * Operators in Java
- Check if count of Alphabets and count of Numbers are equal in the given String
- Expression contains redundant bracket or not
- Lambda Expressions | Concurrent Programming Approach 4
- How to check string is alphanumeric or not using Regular Expression
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Check if words are sorted according to new order of alphabets
- Check if a string contains a palindromic sub-string of even length
- Sort an alphanumeric string such that the positions of alphabets and numbers remain unchanged
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.