Introduction
The isIdentifierIgnorable(char ch)
method is a part of the Character
class in Java. This method is used to check whether a specific character can be considered as an ignorable character in Java or a Unicode identifier or not.
The isIdentifierIgnorable(char ch)
method is a part of the Character
class in Java. This method is used to check whether a specific character can be considered as an ignorable character in Java or a Unicode identifier or not.
Declare the main
method, which is the entry point of the Java program, as shown below:
public static void main(String[] args) {
// your code here
}
Create some variables with different characters, as shown below:
char ch1 = '\u0000'; // ASCII null character
char ch2 = '\u001F'; // ASCII unit separator character
char ch3 = '\u007F'; // ASCII delete character
char ch4 = 'a'; // a normal character
Using the Character.isIdentifierIgnorable(char ch)
method, print whether each character is an ignorable character in Java or Unicode identifier.
System.out.println("Is " + ch1 + " ignorable? " + Character.isIdentifierIgnorable(ch1));
System.out.println("Is " + ch2 + " ignorable? " + Character.isIdentifierIgnorable(ch2));
System.out.println("Is " + ch3 + " ignorable? " + Character.isIdentifierIgnorable(ch3));
System.out.println("Is " + ch4 + " ignorable? " + Character.isIdentifierIgnorable(ch4));
Here is the complete code for your reference:
public class IdentifierIgnorable {
public static void main(String[] args) {
char ch1 = '\u0000'; // ASCII null character
char ch2 = '\u001F'; // ASCII unit separator character
char ch3 = '\u007F'; // ASCII delete character
char ch4 = 'a'; // a normal character
System.out.println("Is " + ch1 + " ignorable? " + Character.isIdentifierIgnorable(ch1));
System.out.println("Is " + ch2 + " ignorable? " + Character.isIdentifierIgnorable(ch2));
System.out.println("Is " + ch3 + " ignorable? " + Character.isIdentifierIgnorable(ch3));
System.out.println("Is " + ch4 + " ignorable? " + Character.isIdentifierIgnorable(ch4));
}
}
Compile the Java program using the following command in the terminal:
javac ~/project/IdentifierIgnorable.java
Run the Java program using the following command:
java IdentifierIgnorable
The program will output the result of whether each character is an ignorable character in Java or Unicode identifier.
Is ignorable? true
Is ignorable? true
Is ignorable? true
Is a ignorable? false
You can test the program with different characters and check their output.
Try modifying the program to take input from the user and check if the character is an ignorable character in Java or a Unicode identifier. Here is the modified code:
import java.util.Scanner;
public class IdentifierIgnorable {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = input.next().charAt(0);
System.out.println("Is " + ch + " ignorable? " + Character.isIdentifierIgnorable(ch));
}
}
Compile the modified Java program using the following command in the terminal:
javac ~/project/IdentifierIgnorable.java
Run the modified Java program using the following command:
java IdentifierIgnorable
The program will ask for a character as input and output whether it is an ignorable character in Java or Unicode identifier.
Enter a character:
$
Is $ ignorable? false
In this lab, you have learned:
isIdentifierIgnorable(char ch)
method is used to check whether a character can be considered as an ignorable character in Java or a Unicode identifier.FORMAT
general category value, are considered as ignorable characters or Unicode identifier.