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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java Lambda Expression with Collections
- Check if a string contains only alphabets in Java
- Check if a string contains only alphabets in Java using Regex
- Check if a string contains only alphabets in Java using ASCII values
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Difference between Anonymous Inner Class and Lambda Expression
- Map function and Lambda expression in Python to replace characters
- How to check string is alphanumeric or not using Regular Expression
- Check if a binary string has a 0 between 1s or not | Set 2 (Regular Expression Approach)
- Check if count of Alphabets and count of Numbers are equal in the given String
- Lambda Expressions in Java 8
- Check if words are sorted according to new order of alphabets
- Remove all characters other than alphabets from string
- Generate a string with maximum possible alphabets with odd frequencies
- Sub-string that contains all lowercase alphabets after performing the given operation
- Sort an alphanumeric string such that the positions of alphabets and numbers remain unchanged
- Check for string rotation in Java
- How to check if string contains only digits in Java
- Check if a given string is Pangram in Java
- Check for balanced parentheses in an expression
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.