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.
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;
public static boolean isAlpha(final CharSequence cs)
CharSequence cs
: Character sequence to check.The function returns true
if the character sequence contains only Unicode characters. Otherwise, it returns false
.
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));}}
""
Since the string is empty, the function returns false
.
"ñå"
Since the string contains Unicode characters, the function returns true
.
null
Since the string is null
, the function returns false
.
The output of the code is as follows:
false
true
false