VOOZH about

URL: https://www.geeksforgeeks.org/java/check-if-a-string-contains-only-alphabets-in-java-using-lambda-expression/

⇱ Check if a String Contains Only Alphabets in Java Using Lambda Expression - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if a String Contains Only Alphabets in Java Using Lambda Expression

Last Updated : 20 Feb, 2026

Lambda Expressions in Java provide a concise way to represent a method using an expression instead of a full method definition. Validating strings to ensure they contain only alphabets becomes simple and readable with them.

Problem Statement

We need to check whether a given string contains only Alphabet letters.

  • Alphabets include A-Z and a-z only.
  • Strings with numbers, spaces, or special characters are considered invalid.

Input: HelloWorld
Output: true

Input: Java123
Output: false

Input: Hello World
Output: false

Approach

  • Convert the input string into a stream of characters using chars().
  • Use allMatch() with Character::isLetter to check if every character is an alphabet.
  • Store the result in a boolean variable.
  • Print the boolean result (true if all letters, otherwise false).

Output
true

Related Articles:

Comment