Store unicode in a char variable in Java


To store Unicode in a char variable, simply create a char variable.

char c;

Now assign unicode.

char c = '\u00AB';

The following is the complete example that shows what will get displayed: when Unicode is stored in a char variable and displayed.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      int a = 79;
      System.out.println(a);
      char b = (char) a;
      System.out.println(b);
      char c = '\u00AB';
      System.out.println(c);
   }
}

Output

79
O
«

Updated on: 26-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements