Given a string, the task is to write a Java program to check whether the string contains only alphabets or not. If so, then print true, otherwise false.
Explanation: The given string contains only alphabets so the output is true.
Explanation: The given string contains alphabets and numbers so the output is false.
Explanation: The given string is empty so the output is false.
Method 4: This approach uses the methods of Character class in Java
- The idea is to iterate over each character of the string and check whether the specified character is a letter or not using Character.isLetter() method.
- If the character is a letter then continue, else return false.
- If we are able to iterate over the whole string, then return true.
Below is the implementation of the above approach:
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.
- 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 string contains only alphabets in Java using Lambda expression
- Check if count of Alphabets and count of Numbers are equal in the given String
- 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
- How to check if string contains only digits in Java
- Check for string rotation in Java
- Program to check if a String in Java contains only whitespaces
- Check if a String starts with any of the given prefixes in Java
- Program to check if the String is Null in Java
- Program to check if the String is Empty in Java
- Java program to check whether a string is a Palindrome
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- String slicing in Python to check if a string can become empty by recursive deletion
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.