Character 类的 isValidCodePoint(int codePoint) 方法确定给定(或指定)字符是否是有效的 Unicode 代码点。
用法
public static boolean isValidCodePoint(int codePoint)
参数
上述方法只需要一个参数:
a.) codePoint 是需要测试的字符。
返回值
isValidCodePoint(int codePoint) 方法返回一个布尔值,即如果给定(或指定)字符位于 MIN_CODE_POINT 和 MAX_CODE_POINT 之间的范围内,则返回 true。否则,此方法返回 false。
例子1
public class JavaCharacterisValidCodePointExample1 {
public static void main(String[] args) {
// Initialize the codepoints:cp1, cp2, cp3 and cp4
int cp1 = 12;
int cp2 = 51;
int cp3 = 121;
int cp4 = 160;
// Check whether the codepoints are valid or not.
boolean result1 = Character.isValidCodePoint(cp1);
boolean result2 = Character.isValidCodePoint(cp2);
boolean result3 = Character.isValidCodePoint(cp3);
boolean result4 = Character.isValidCodePoint(cp4);
// Print the results.
System.out.println("The codePoint '"+ cp1 + "' is a valid codepoint:"+result1);
System.out.println("The codePoint '"+ cp2 + "' is a valid codepoint:"+result2);
System.out.println("The codePoint '"+ cp3 + "' is a valid codepoint:"+result3);
System.out.println("The codePoint '"+ cp4 + "' is a valid codepoint:"+result4);
}
}
输出:
The codePoint '12' is a valid codepoint:true The codePoint '51' is a valid codepoint:true The codePoint '121' is a valid codepoint:true The codePoint '160' is a valid codepoint:true
例子2
public class JavaCharacterisValidCodePointExample2 {
public static void main(String[] args) {
//Create four int primitives cp1, cp2, cp3 and cp4.
int cp1, cp2, cp3, cp4;
// Assign the values to ch1, ch2, ch3 and ch4.
cp1 = 121;
cp2 = 128;
cp3 = 227;
cp4 = 342;
// Create four boolean primitives b1, b2, b3 and b4.
boolean b1, b2, b3, b4;
b1 = Character.isValidCodePoint(cp1);
b2 = Character.isValidCodePoint(cp2);
b3 = Character.isValidCodePoint(cp3);
b4 = Character.isValidCodePoint(cp4);
// Print the values.
String str1 = "The first codePoint '"+cp1+"' is a valid codePoint:"+ b1;
String str2 = "The second codePoint '"+cp2+"' is a valid codePoint:"+ b2;
String str3 = "The third codePoint '"+cp3+"' is a valid codePoint :"+ b3;
String str4 = "The fourth codePoint '"+cp4+"' is a valid codePoint:"+ b4;
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
}
}
输出:
The first codePoint '121' is a valid codePoint:true The second codePoint '128' is a valid codePoint:true The third codePoint '227' is a valid codePoint :true The fourth codePoint '342' is a valid codePoint:true
例子3
public class JavaCharacterisValidCodePointExample3 {
public static void main(String[] args) {
//Create four int primitives cp1, cp2, cp3 and cp4.
int cp1, cp2, cp3, cp4;
// Assign the values to ch1, ch2, ch3 and ch4.
cp1 = 323;
cp2 = 345;
cp3 = 564;
cp4 = 787;
// Create four boolean primitives b1, b2, b3 and b4.
boolean b1, b2, b3, b4;
b1 = Character.isValidCodePoint(cp1);
b2 = Character.isValidCodePoint(cp2);
b3 = Character.isValidCodePoint(cp3);
b4 = Character.isValidCodePoint(cp4);
// Print the values.
System.out.println("The first codePoint '"+cp1+"' is a valid codePoint:"+ b1);
System.out.println("The second codePoint '"+cp2+"' is a valid codePoint:"+ b2);
System.out.println("The third codePoint '"+cp3+"' is a valid codePoint:"+ b3);
System.out.println("The fourth codePoint '"+cp4+"' is a valid codePoint:"+ b4);
}
}
输出:
The first codePoint '323' is a valid codePoint:true The second codePoint '345' is a valid codePoint:true The third codePoint '564' is a valid codePoint:true The fourth codePoint '787' is a valid codePoint:true
相关用法
- Java Character isLetter()用法及代码示例
- Java Character isAlphabetic()用法及代码示例
- Java Character isISOControl()用法及代码示例
- Java Character isSpace()用法及代码示例
- Java Character isMirrored()用法及代码示例
- Java Character isBmpCodePoint()用法及代码示例
- Java Character isIdentifierIgnorable()用法及代码示例
- 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 isValidCodePoint() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。