Character.charCount() 메서드는 지정된 문자(유니코드 코드 포인트)를 나타내는 데 필요한 char 값의 수를 결정합니다. 지정된 문자가 0x10000보다 크거나 같으면 2를 반환하고, 그렇지 않으면 1을 반환합니다.
예
이제 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args) {
// create and assign values to int codepoint cp
int cp = 0x12345;
// create an int res
int res;
// assign the result of charCount on cp to res
res = Character.charCount(cp);
String str1 = "It is not a valid supplementary character";
String str2 = "It is a valid supplementary character";
// print res value
if ( res == 1 ) {
System.out.println( str1 );
} else if ( res == 2 ) {
System.out.println( str2 );
}
}
} 출력
It is a valid supplementary character
예
다른 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args) {
int c = 0x11987;
int res = Character.charCount(c);
System.out.println(res);
}
} 출력
2