Char in Java for the character: two bytes
1) char type uses the Unicode character set encoding, a code corresponding to a character, the character is realized in the form of char, but is essentially a int, we know (ASCII code: 'a'-97' A'- 65 ' 0'-48), then how to convert it. Click to view ASCII table
2) Check the value corresponding to an int char ASCII code:
package demo;
public class AsciiDemo {
public static void main(String[] args) {
char ch = 97;
System.out.println(ch);
char ch1 = 'a';
System.out.println(ch==ch1);
}
}
Output code below: Description directly output char ch = 97; int can know a value corresponding to 97 char ASCII value is.
3) Check the ASCII char int value corresponding to:
If you attempt to directly output a: Let's try this:
package demo;
public class AsciiDemo {
public static void main(String[] args) {
char ch = 'a';
System.out.println(ch);
}
}
Then the result will be directly output a.
a, direct conversion: 97 and output true, successful conversion.
package day01;
public class AsciiDemo {
public static void main(String[] args) {
char ch = 'a';
int intValue = ch;
System.out.println(intValue); //97
System.out.println(ch==intValue); //true
}
}
b, we can convert it to achieve the following codes: output: 97 and true, a successful conversion.
package demo;
public class AsciiDemo {
public static void main(String[] args) {
char ch = 'a';
System.out.println(ch+0); //97
System.out.println(ch==97); //true
}
}
Because the java basic type of calculation will be converted to int type calculation, we operate through ch + 0, the first ch converted to int, then +0, in fact, and did not add the same, that is, per se ch int value, in order to achieve the ASCII value of char to int values.