How to convert a character (Unicode code point) to UTF-16 and store in a char array in Java

2 Answers

0 votes
package javaapplication1;
  
import java.util.Arrays;

public class JavaApplication1 {
  
    public static void main(String[] args) {
  
        char ch[];

        int cp = 0x005a;

        ch = Character.toChars(cp);

        System.out.print(Arrays.toString(ch));
    }
}
  
/*
run:
 
[Z]
  
*/

 



answered Sep 17, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {
  
    public static void main(String[] args) {
  
        char ch[];

        int cp = 0x005a;

        ch = Character.toChars(cp);

        for (int i=0; i < ch.length; i++)
            System.out.print(ch[i]);
        
        System.out.println();
    }
}
  
/*
run:
 
Z
  
*/

 



answered Sep 17, 2016 by avibootz
...