- Java.lang 包类
- Java.lang - 首页
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang 包附加内容
- Java.lang - 接口
- Java.lang - 错误
- Java.lang - 异常
- Java.lang 包有用资源
- Java.lang - 有用资源
- Java.lang - 讨论
Java Character isLowSurrogate() 方法
描述
Java Character isLowSurrogate(char ch) 方法用于确定给定的 char 值是否为 Unicode 低代理单元(也称为尾随代理单元)。
此类值本身并不代表字符,而是用于在 UTF-16 编码中表示补充字符。
声明
以下是 java.lang.Character.isLowSurrogate() 方法的声明
public static boolean isLowSurrogate(char ch)
参数
ch − 要测试的 char 值
返回值
如果 char 值在 MIN_LOW_SURROGATE 和 MAX_LOW_SURROGATE(包含)之间,则此方法返回 true;否则返回 false。
异常
无
检查字符是否为低代理的示例
以下示例演示了 Java Character isLowSurrogate() 方法的用法。在此示例中,我们创建了两个 char 变量并为它们分配了两个 Unicode 值。现在,使用 isLowSurrogate() 方法,我们检查这些 char 值是否在低代理范围内。
package com.tutorialspoint; public class CharacterDemo { public static void main(String[] args) { // create 2 char primitives ch1, ch2 char ch1, ch2; // assign values to ch1, ch2 ch1 = '\udc28'; ch2 = 'a'; // create 2 boolean primitives b1, b2 boolean b1, b2; /** * check if ch1, ch2 are Unicode low-surrogate code units * and assign results to b1, b2 */ b1 = Character.isLowSurrogate(ch1); b2 = Character.isLowSurrogate(ch2); String str1 = "ch1 is a Unicode low-surrogate is " + b1; String str2 = ch2 + " is a Unicode low-surrogate is " + b2; // print b1, b2 values System.out.println( str1 ); System.out.println( str2 ); } }
让我们编译并运行上述程序,这将产生以下结果:
ch1 is a Unicode low-surrogate is true a is a Unicode low-surrogate is false
检查字符是否为低代理的示例
以下示例演示了 Java Character isLowSurrogate() 方法的用法。在此示例中,我们创建了两个 char 变量并为它们分配了两个 Unicode 值。现在,使用 isLowSurrogate() 方法,我们检查这些 char 值是否在低代理范围内。
package com.tutorialspoint; public class CharacterDemo { public static void main(String[] args) { // create 2 char primitives ch1, ch2 char ch1, ch2; // assign values to ch1, ch2 ch1 = '\u0c7f'; ch2 = '\ud8b5'; // create 2 boolean primitives b1, b2 boolean b1, b2; // assign isLowSurrogate results of ch1, ch2 to b1, b2 b1 = Character.isLowSurrogate(ch1); b2 = Character.isLowSurrogate(ch2); String str1 = "ch1 is a Unicode low-surrogate code unit is " + b1; String str2 = "ch2 is a Unicode low-surrogate code unit is " + b2; // print b1, b2 values System.out.println( str1 ); System.out.println( str2 ); } }
输出
让我们编译并运行上述程序,这将产生以下结果:
ch1 is a Unicode low-surrogate code unit is false ch2 is a Unicode low-surrogate code unit is false
检查字符是否为低代理的示例
另一个示例程序使用条件语句来确定传递的参数是否为高代理,因为此方法的返回类型是布尔型,如下所示:
package com.tutorialspoint; public class Demo { public static void main(String[] args) { char ch1 = '\ud800'; if(Character.isLowSurrogate(ch1)) System.out.println("The character is a Unicode low-surrogate code unit"); else System.out.println("The character is not a Unicode low-surrogate code unit"); } }
输出
方法执行后,将获得并显示以下输出:
The character is not a Unicode low-surrogate code unit
java_lang_character.htm
广告