字符类的 isLowSurrogate(char ch) 方法确定给定(或指定)字符是否为 Unicode 低代理代码单元(也称为 trailing-surrogate 代码单元)。
这些值本身并不代表字符,而是用来代表UTF-26编码中的增补字符。
用法
public static boolean isLowSurrogate(char ch)
参数
ch: 这是需要测试的字符。
返回值
isLowSurrogate(char ch) 方法返回一个布尔值,即如果给定(或指定)字符位于 MIN_LOW_SURROGATE 和 MAX_LOW_SURROGATE 之间,则返回 true。否则,该方法返回 false。
例子1
public class JavaCharacterIsLowSurrogateExample1 {
public static void main(String[] args) {
// Create three char primitives ch1, ch2 and ch3.
char ch1, ch2, ch3;
// Assign the values to ch1, ch2 and ch3.
ch1 = '\udc34';
ch2 = 'a';
ch3 = 'Y';
// Create three boolean primitives b1, b2 and b3.
boolean b1, b2, b3;
b1 = Character.isLowSurrogate(ch1);
b2 = Character.isLowSurrogate(ch2);
b3 = Character.isLowSurrogate(ch3);
String str1 = "The first character '"+ch1 + "' is a Unicode low-surrogate:" + b1;
String str2 = "The second character '"+ch2 + "' is a Unicode low-surrogate:" + b2;
String str3 = "The third character '"+ch3 + "' is a Unicode low-surrogate:" + b3;
// Print the values of b1, b2 and b3.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
}
}
输出:
The first character '?' is a Unicode low-surrogate:true The second character 'a' is a Unicode low-surrogate:false The third character 'Y' is a Unicode low-surrogate:false
例子2
public class JavaCharacterIsLowSurrogateExample2 {
public static void main(String[] args) {
// Create four char primitives ch1, ch2, ch3 and ch4.
char ch1, ch2, ch3, ch4;
// Assign the values to ch1, ch2, ch3 and ch4.
ch1 = '*';
ch2 = 'a';
ch3 = 'Y';
ch4 = '#';
// Create four boolean primitives b1, b2, b3 and b4.
boolean b1, b2, b3, b4;
b1 = Character.isLowSurrogate(ch1);
b2 = Character.isLowSurrogate(ch2);
b3 = Character.isLowSurrogate(ch3);
b4 = Character.isLowSurrogate(ch4);
String str1 = "The first character '"+ch1 + "'is a Unicode low-surrogate:" + b1;
String str2 = "The second character '"+ch2 + "' is a Unicode low-surrogate:" + b2;
String str3 = "The third character '"+ch3 + "' is a Unicode low-surrogate:" + b3;
String str4 = "The fourth character '"+ch4+ "' is a Unicode low-surrogate:" + b4;
//Print the values of b1, b2, b3 and b4.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
System.out.println( str4 );
}
}
输出:
The first character '*'is a Unicode low-surrogate:false The second character 'a' is a Unicode low-surrogate:false The third character 'Y' is a Unicode low-surrogate:false The fourth character '#' is a Unicode low-surrogate:false
例子3
import java.util.Scanner;
public class JavaCharacterIsLowSurrogateExample3 {
public static void main(String[] args) {
// Ask the user for the first input.
System.out.print("Enter the first input:");
// Use the Scanner class to get the user input.
Scanner s1 = new Scanner(System.in);
// Gets the user input.
char[] value1 = s1.nextLine().toCharArray();
// Check whether the user input is a low surrogate or not.
for (char ch1:value1) {
boolean result1 = Character.isLowSurrogate(ch1);
// print the result
if(result1){
System.out.println("The character '" + ch1 + "' is a low-surrogate. ");
}
else{
System.out.println("The character '" + ch1 + "' is not a low-surrogate.");
}
System.out.print("Enter the second input:");
Scanner s2 = new Scanner(System.in);
char[] value2 = s2.nextLine().toCharArray();
for (char ch2:value2) {
boolean result2 = Character.isLowSurrogate(ch2);
if(result2){
System.out.println("The character '" + ch2 + "' is a low-surrogate. ");
}
else{
System.out.println("The character '" + ch2 + "' is not a low-surrogate.");
}
System.out.print("Enter the third input:");
Scanner s3 = new Scanner(System.in);
char[] value3 = s3.nextLine().toCharArray();
for (char ch3:value3) {
boolean result3 = Character.isLowSurrogate(ch3);
if(result2){
System.out.println("The character '" + ch3 + "' is a low-surrogate. ");
}
else{
System.out.println("The character '" + ch3 + "' is not a low-surrogate..");
}
}
}
}
}
}
输出:
Enter the first input:H The character 'H' is not a low-surrogate. Enter the second input:) The character ')' is not a low-surrogate. Enter the third input:6 The character '6' is not a low-surrogate..
相关用法
- Java Character isLowerCase()用法及代码示例
- Java Character isLetter()用法及代码示例
- Java Character isLetterOrDigit()用法及代码示例
- Java Character isAlphabetic()用法及代码示例
- Java Character isValidCodePoint()用法及代码示例
- Java Character isISOControl()用法及代码示例
- Java Character isSpace()用法及代码示例
- Java Character isMirrored()用法及代码示例
- Java Character isBmpCodePoint()用法及代码示例
- Java Character isIdentifierIgnorable()用法及代码示例
- Java Character isDigit()用法及代码示例
- Java Character isJavaIdentifierPart()用法及代码示例
- Java Character isUpperCase()用法及代码示例
- Java Character isJavaLetterOrDigit()用法及代码示例
- Java Character isWhitespace()用法及代码示例
- Java Character isDefined()用法及代码示例
- Java Character isJavaIdentifierstart()用法及代码示例
- Java Character isHighSurrogate()用法及代码示例
- Java Character isSpaceChar()用法及代码示例
- Java Character codePointCount()用法及代码示例
注:本文由纯净天空筛选整理自 Java Character isLowSurrogate() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。