Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
stringutils
communitycreator

What is StringUtils.isAlpha in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

isAlpha is a static method of the StringUtils class that checks whether a given string contains only Unicode characters. The function returns false if the input string is null or empty.

How to import StringUtils

The definition for StringUtils can be found in the Apache Commons Lang package. The Apache Commons Lang can be added to the Maven project by adding the using dependency to the pom.xml file.

<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
</dependency>

Note: For other versions of the commons-lang package, review the Maven Repository.

You can import the StringUtils class as follows:

import org.apache.commons.lang3.StringUtils;

Syntax


public static boolean isAlpha(final CharSequence cs)

Parameters

  • CharSequence cs: Character sequence to check.

Return value

The function returns true if the character sequence contains only Unicode characters. Otherwise, it returns false.

Code

import org.apache.commons.lang3.StringUtils;
public class Main{
public static void main(String[] args){
String characterSequence = "";
System.out.println(StringUtils.isAlpha(characterSequence));
characterSequence = "ñå";
System.out.println(StringUtils.isAlpha(characterSequence));
System.out.println(StringUtils.isAlpha(null));
}
}

Explanation

  1. string = ""

Since the string is empty, the function returns false.

  1. string = "ñå"

Since the string contains Unicode characters, the function returns true.

  1. string = null

Since the string is null, the function returns false.

Output

The output of the code is as follows:


false
true
false

RELATED TAGS

java
stringutils
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring