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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] codePoints = "🥦_Salade".codePoints().toArray() ;
  13. System.out.println( Arrays.toString( codePoints ) ) ;
  14.  
  15. int codePoint = codePoints[ 0 ] ;
  16. String firstCharacter = Character.toString( codePoint ) ;
  17. System.out.println( "firstCharacter = " + firstCharacter ) ;
  18.  
  19. int[] firstFewCodePoints = Arrays.copyOfRange( codePoints , 0 , 3 ) ;
  20. String s =
  21. .stream( firstFewCodePoints )
  22. .collect( StringBuilder::new , StringBuilder::appendCodePoint , StringBuilder::append )
  23. .toString();
  24. System.out.println( "s = " + s ) ;
  25.  
  26. String result = new String( codePoints , 0 , 3 ) ;
  27. System.out.println( "result = " + result ) ;
  28.  
  29. }
  30. }
Success #stdin #stdout 0.11s 54704KB
stdin
Standard input is empty
stdout
[129382, 95, 83, 97, 108, 97, 100, 101]
firstCharacter = 🥦
s = 🥦_S
result = 🥦_S