Java char type unicode literal

Question

We would like to create a char type and assign a unicode literal to it.

Character A's Unicode is 0041

public class Main {
  public static void main(String[] args) {
    char letter =  'A'; 
    char letter1 =  //your code here 

    
   System.out.println(letter == letter1 );
  }
}


public class Main {
  public static void main(String[] args) {
    char letter =  'A'; 
    char letter1 =  '\u0041';  

    
   System.out.println(letter == letter1 );
  }
}

Note

You can use ASCII characters such as 'X', '1', and '$' in a Java program as well as Unicode.

Thus, for example, the following statements are equivalent:

char letter =  'A'; 
char letter =  '\u0041'; // Character A's Unicode is 0041 



PreviousNext

Related