What is a char code delivery method?

I need to do some things with code points and a new line. I have a function that accepts code char, and if it is \r, it should behave differently. I have it:

if (codePoint == Character.codePointAt(new char[] {'\r'}, 0)) {

but this is very ugly and certainly not the right way to do this. What is the right way to do this?

(I know that I could hardcode the number 13(decimal identifier for \r) and use it, but that would make it unclear what I am doing ...)

+4
source share
2 answers

, (U + 0000 U + FFFF), :

char character = 'x';
int codePoint = character;

char int, JLS 5.1.2:

19 :

  • ...
  • char int, long, float double

...

char T zero - char .

a char - UTF-16. Character.codePointAt , BMP, - UTF-16, , .

JLS 3.1:

Unicode 16- . , , 16 . U + 0000 U + 10FFFF, U + n . , U + FFFF, . , 16- , Unicode UTF-16. 16- , (U + D800 U + DBFF), (U + DC00 U + DFFF). U + 0000 U + FFFF UTF-16 .

, .

+6

, char int, -

char ch = '\r';
int codePoint = (int) ch;
System.out.println(codePoint);

13
+4

All Articles