- java.lang.Character.isIdentifierIgnorable(char ch)是java中的一种内置方法,该方法确定应将指定字符视为Java标识符还是Unicode标识符中的可忽略字符。
以下Unicode字符在Java标识符或Unicode标识符中可忽略:
- 非空白的ISO控制字符
- “ \ u0000”到“ \ u0008”
- “ \ u000E”到“ \ u001B”
- 从'\ u007F'到'\ u009F'
- 具有FORMAT常规类别值的所有字符
用法:
public static boolean isIdentifierIgnorable(char ch)
参数:参数ch是字符数据类型,是指要测试的字符。
返回值:如果该字符是Java或Unicode标识符的一部分的可忽略控制字符,则此方法返回true,否则返回false。
以下示例程序旨在说明Character.isIdentifierIgnorable(char ch)方法:
示例1:
// Java program to illustrate // Character.isIdentifierIgnorable(char ch) method import java.lang.*; public class gfg { public static void main(String[] args) { // Creates 2 character primitives c1, c2 and assigning values char c1='\u0000', c2= '9'; // Assigns isIdentifierIgnorable results of // c1, c2 to boolean primitives boolean bool1 = Character.isIdentifierIgnorable(c1); boolean bool2 = Character.isIdentifierIgnorable(c2); String str1 = "c1 is an ignorable control character is " + bool1; String str2 = "c2 is an ignorable control character is " + bool2; System.out.println( str1 ); System.out.println( str2 ); } }
输出:c1 is an ignorable control character is true c2 is an ignorable control character is false
示例2:
import java.lang.*; public class gfg { public static void main(String[] args) { // Create 2 character primitives c1, c2 and assigning values char c1='\u000E', c2= '8'; // Assigns isIdentifierIgnorable results of // c1, c2 to boolean primitives boolean bool1 = Character.isIdentifierIgnorable(c1); boolean bool2 = Character.isIdentifierIgnorable(c2); String str1 = "c1 is an ignorable control character is " + bool1; String str2 = "c2 is an ignorable control character is " + bool2; System.out.println( str1 ); System.out.println( str2 ); } }
输出:c1 is an ignorable control character is true c2 is an ignorable control character is false
- 非空白的ISO控制字符
- java.lang.Character.isIdentifierIgnorable(int codePoint)在所有方面都类似于先前的方法。
用法:
public static boolean isIdentifierIgnorable(int codePoint)
参数:该函数接受整数数据类型的单个参数codePoint,该参数指定要测试的字符(Unicode代码点)。
返回值:如果该字符是Java或Unicode标识符的一部分的可忽略控制字符,则此方法返回true,否则返回false。
以下示例程序旨在说明Character.isIdentifierIgnorable(int codepoint)方法:
示例1:// Java program to demonstrate // the Character.isIdentifierIgnorable(int codepoint) method import java.lang.*; public class gfg { public static void main(String[] args) { // Integer primitives c1, c2 int c1 = 0x019f, c2 = 0x1abc; // Assign isIdentifierIgnorable results of cp1, cp2 // to boolean primitives bool1, bool2 boolean bool1 = Character.isIdentifierIgnorable(c1); boolean bool2 = Character.isIdentifierIgnorable(c2); // Print bool1, bool2 values System.out.println( "c1 is an ignorable control character?"+ " ans is "+bool1); System.out.println( "c2 is an ignorable control character?"+ " ans is "+bool2); } }
输出:c1 is an ignorable control character? ans is false c2 is an ignorable control character? ans is false
示例2:
// Java program to demonstrate // the Character.isIdentifierIgnorable(int codepoint) method import java.lang.*; public class gfg { public static void main(String[] args) { // Integer primitives c1, c2 int c1 = 0x119f, c2 = 0x0abc; // Assign isIdentifierIgnorable results of cp1, cp2 // to boolean primitives bool1, bool2 boolean bool1 = Character.isIdentifierIgnorable(c1); boolean bool2 = Character.isIdentifierIgnorable(c2); // Print bool1, bool2 values System.out.println( "c1 is an ignorable control character?"+ " ans is "+bool1); System.out.println( "c2 is an ignorable control character?"+ " ans is "+bool2); } }
输出:c1 is an ignorable control character? ans is false c2 is an ignorable control character? ans is false
参考: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isIdentifierIgnorable(char)
相关用法
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.highestOneBit()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java.util.concurrent.Phaser用法及代码示例
- Java Java.util.concurrent.RecursiveTask用法及代码示例
- Java Java.util.function.BiPredicate用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
- Java Java.util.function.IntPredicate用法及代码示例
- Java Java.util.function.DoublePredicate用法及代码示例
注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 Character.isIdentifierIgnorable() in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。