0

I have a string with an emoji in it: "test ". When I use .toCharArray() on it I get "t", "e", "s", "t", " ", "?", "?". I'm expecting "t", "e", "s", "t", " ", "". How can I accomplish this in Java?

V0idst4r
  • 91
  • 1
  • 3
  • I believe you would need to use something different than the default UTF8 in order to see that. – Travis J Apr 03 '18 at 18:56
  • 1
    A single char cannot hold an emoji, or any other supplemental codepoint, so you will need an array of ints instead. – VGR Apr 03 '18 at 18:59
  • Yeah I know that's why I said or strings. – V0idst4r Apr 03 '18 at 19:03
  • I don't think the answers for that question satisfy mine. I have found a solution though using some information provided there. (But it still needed work) – V0idst4r Apr 03 '18 at 19:22

1 Answers1

0

Because Java characters cannot hold codepoints (emoji in this case) which equate to multiple characters I used

string.codePoints().mapToObj(Character::toChars).map(chars -> CharBuffer.wrap(chars).toString())

to instead get a stream of strings which hold each codepoints characters.

V0idst4r
  • 91
  • 1
  • 3