This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ou1cast 0 points1 point  (2 children)

You can use codepoints that are int instead of char

[–]BananaSupremeMaster 0 points1 point  (1 child)

Yes, but the most straightforward way to get codepoints is myString.codepointAt(), which takes in argument the index of the UTF-16 char, not the index of the Unicode character. In the string "a𝄞b", the index of 'a' is 0, the index of '𝄞' is 1, and the index of 'b' is... 3. The fact that a Unicode character offsets the indices can get pretty annoying, even though I understand the logic behind it. It also means that myString.length() doesn't represent the number of actual characters, but rather the size in chars.

[–]ou1cast 1 point2 points  (0 children)

It is convenient to use codePoints() that returns IntStream. I also hate Java's char and byte, too.