fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.util.stream.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String input = "dog🐶" ;
  15. List < Integer > codePoints = input.codePoints().boxed().collect( Collectors.toList() );
  16. String output =
  17. codePoints
  18. .stream()
  19. .collect( StringBuilder :: new , StringBuilder :: appendCodePoint , StringBuilder :: append )
  20. .toString();
  21.  
  22. System.out.println( "input: " + input ) ;
  23. System.out.println( "codePoints: " + codePoints ) ;
  24. System.out.println( "output: " + output ) ;
  25.  
  26. String result = Ideone.listOfCodePointsToString( codePoints ) ;
  27. System.out.println( "result: " + result ) ;
  28. }
  29.  
  30. public static final String listOfCodePointsToString( List< Integer > codePoints )
  31. {
  32. String output =
  33. codePoints
  34. .stream()
  35. .filter( codePoint -> Character.isValidCodePoint( codePoint ) )
  36. .collect( StringBuilder :: new , StringBuilder :: appendCodePoint , StringBuilder :: append )
  37. .toString();
  38. return output ;
  39. }
  40. }
Success #stdin #stdout 0.11s 55252KB
stdin
Standard input is empty
stdout
input: dog🐶
codePoints: [100, 111, 103, 128054]
output: dog🐶
result: dog🐶