Character 类的 isIdentifierIgnorable(int codePoint) 方法一般决定指定的字符是否可以被视为 Java 中的可忽略字符或 Unicode 标识符。
以下字符在 Java 或 Unicode 标识符中被视为可忽略字符:
- 没有空格的 ISO 控制字符。
- 所有具有 FORMAT 通用类别值的字符。
用法
public static boolean isIdentifierIgnorable(int codePoint)
参数
上述方法只需要一个参数:
a.)codePoint 是需要测试的字符。
返回值
isIdentifierIgnorable(int codePoint) 方法返回一个布尔值,即如果给定(或指定)字符是一个可忽略的控制字符,它可能是 Java 或 Unicode 标识符的一部分,则返回 true。否则,此方法返回 false。
例子1
public class JavaCharacterisIdentifierIgnorableintcodePointExample1 {
public static void main(String[] args) {
// Create three int primitives codePoint1, codePoint2 and codePoint3.
int codePoint1, codePoint2, codePoint3;
// Assign the values to codePoint1, codePoint2 and codePoint3;
codePoint1 = 0x008f;
codePoint2 = 0x0abc;
codePoint3 = 0x0a76;
// Create three boolean primitives b1, b2 and b3;
boolean b1, b2, b3;
// Assign the results of isIdentifierIgnorable of codePoint1, codePoint2 and codePoint3 to b1, b2and b3 respectively.
b1 = Character.isIdentifierIgnorable(codePoint1);
b2 = Character.isIdentifierIgnorable(codePoint2);
b3 = Character.isIdentifierIgnorable(codePoint3);
System.out.println("The first codePoint is an ignorable control character is: "+ b1);
System.out.println("The second codePoint is an ignorable control character is:"+ b2);
System.out.println("The third codePoint is an ignorable control character is: "+ b3);
}
}
输出:
The first codePoint is an ignorable control character is: true The second codePoint is an ignorable control character is:false The third codePoint is an ignorable control character is: false
例子2
public class JavaCharacterisIdentifierIgnorableintcodePointExample2 {
public static void main(String[] args) {
// Create the integer primitives c1 and c2 and assign the values to them.
int c1 = 0x119f;
int c2 = 0x0abc;
// Create two boolean primitives b1 and b2.
boolean b1 = Character.isIdentifierIgnorable(c1);
boolean b2 = Character.isIdentifierIgnorable(c2);
// Print the values of b1 and b2.
System.out.println( "The first codePoint is an ignorable control character: " + b1);
System.out.println( "The second codePoint is an ignorable control character:" + b2);
}
}
输出:
The first codePoint is an ignorable control character: false The second codePoint is an ignorable control character:false
Java 字符 isIdentifierIgnorable() 方法
Character 类的 isIdentifierIgnorable(char ch) 方法一般判断指定的字符是否可以视为 Java 中的可忽略字符或 Unicode 标识符。
以下字符在 Java 或 Unicode 标识符中被视为可忽略字符:
- 没有空格的 ISO 控制字符。
- 所有具有 FORMAT 通用类别值的字符。
注意:上述方法不能用于处理增补字符。为了支持所有 Unicode 字符,包括增补字符,我们可以使用 isIdentifierIgnorable(int codePoint) 方法。
用法
public static boolean isIdentifierIgnorable(char ch)
参数
上述方法只需要一个参数:
a.)需要测试的字符。
返回值
isIdentifierIgnorable(char ch) 方法返回一个布尔值,即如果给定(或指定)字符是可忽略的控制字符,并且也是 Java 或 Unicode 标识符的一部分,则返回 true。否则,此方法返回 false。
例子3
public class JavaCharacterisIdentifierIgnorableExample3 {
public static void main(String[] args) {
// Create three char primitives char1, char2 and char3.
char char1, char2, char3;
// Assign the values to char1, char2 and char3.
char1 = 'A';
char2 = 'B';
char3 = 'C';
// Create three boolean primitives b1, b2 and b3.
boolean b1, b2, b3;
// Assign isIdentifierIgnorable results of char1, ch2 and ch3 to b1, b2 and b3 respectively.
b1 = Character.isIdentifierIgnorable(char1);
b2 = Character.isIdentifierIgnorable(char2);
b3 = Character.isIdentifierIgnorable(char3);
String str1 = "The first character 'A' is an ignorable control character: " + b1;
String str2 = "The second character 'B' is an ignorable control character:" + b2;
String str3 = "The third character 'C' is an ignorable control character:" + b3;
// Print the values of b1, b2 and b3.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
}
}
输出:
The first character 'A' is an ignorable control character: false The second character 'B' is an ignorable control character:false The third character 'C' is an ignorable control character: false
示例 4
public class JavaCharacterisIdentifierIgnorableExample4 {
public static void main(String[] args) {
// Create three char primitives char1, char2 and char3.
char char1, char2, char3;
// Assign the values to char1, char2 and char3.
char1 = '1';
char2 = '2';
char3 = '3';
// Create three boolean primitives b1, b2 and b3.
boolean b1, b2, b3;
// Assign isIdentifierIgnorable results of char1, ch2 and ch3 to b1, b2 and b3 respectively.
b1 = Character.isIdentifierIgnorable(char1);
b2 = Character.isIdentifierIgnorable(char2);
b3 = Character.isIdentifierIgnorable(char3);
String str1 = "The first character '1' is an ignorable control character: " + b1;
String str2 = "The second character '2' is an ignorable control character: " + b2;
String str3 = "The third character '3' is an ignorable control character: " + b3; // Print the values of b1, b2 and b3.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
}
}
输出:
The first character '1' is an ignorable control character: false The second character '2' is an ignorable control character: false The third character '3' is an ignorable control character: false
例 5
import java.util.Scanner;
public class JavaCharacterisIdentifierIgnorableExample5 {
public static void main(String[] args) {
// Ask the user for the first input.
System.out.print("Enter the first input of your choice:");
// Use Scanner to get the input.
Scanner obj1 = new Scanner(System.in);
char[] value1 = obj1.nextLine().toCharArray();
// Get a value which indicates whether the given character is ignorable or not.
for (char ch1:value1) {
boolean result1 = Character.isIdentifierIgnorable(ch1);
System.out.println("The character '"+ ch1 +"' is an ignorable character:" + result1);
}
// Ask the user for the second input.
System.out.print("Enter the second input of your choice:");
Scanner obj2 = new Scanner(System.in);
char[] value2 = obj1.nextLine().toCharArray();
for (char ch2:value2) {
boolean result2 = Character.isIdentifierIgnorable(ch2); System.out.println("The character '"+ ch2 +"' is an ignorable character:" + result2);
}
}
}
输出:
Enter the first input of your choice:G The character 'G' is an ignorable character:false Enter the second input of your choice:# The character '#' is an ignorable character:false
相关用法
- Java Character isISOControl()用法及代码示例
- Java Character isLetter()用法及代码示例
- Java Character isAlphabetic()用法及代码示例
- Java Character isValidCodePoint()用法及代码示例
- Java Character isSpace()用法及代码示例
- Java Character isMirrored()用法及代码示例
- Java Character isBmpCodePoint()用法及代码示例
- Java Character isDigit()用法及代码示例
- Java Character isLowerCase()用法及代码示例
- Java Character isJavaIdentifierPart()用法及代码示例
- Java Character isUpperCase()用法及代码示例
- Java Character isLowSurrogate()用法及代码示例
- Java Character isJavaLetterOrDigit()用法及代码示例
- Java Character isWhitespace()用法及代码示例
- Java Character isDefined()用法及代码示例
- Java Character isJavaIdentifierstart()用法及代码示例
- Java Character isHighSurrogate()用法及代码示例
- Java Character isLetterOrDigit()用法及代码示例
- Java Character isSpaceChar()用法及代码示例
- Java Character codePointCount()用法及代码示例
注:本文由纯净天空筛选整理自 Java Character isIdentifierIgnorable() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。