Check if the String contains only unicode letters in Java

In order to check if a String has only Unicode letters in Java, we use the isDigit() and charAt() methods with decision-making statements.

The isLetter(int codePoint) method determines whether the specific character (Unicode codePoint) is a letter. It returns a boolean value, either true or false.

Declaration −The java.lang.Character.isLetter() method is declared as follows −

public static boolean isLetter(int codePoint)

Here, the parameter codePoint represents the character to be checked.

The charAt() method returns a character value at a given index. It belongs to the String class in Java. The index must be between 0 to length()-1.

Declaration −The java.lang.String.charAt() method is declared as follows −

public char charAt(int index)

Let us see a program in Java to check if a String has only Unicode Letters.

Example

public class Example {
   boolean check(String s) {
      if (s == null) // checks if the String is null {
         return false;
      }
      int len = s.length();
      for (int i = 0; i 

Output

String @asd has only unicode letters : false
String 134s has only unicode letters : false
String abcd has only unicode letters : true
String g c1 has only unicode letters : false
Updated on: 2020-06-26T09:55:48+05:30

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements