I believe you need to know the difference between ASCII and Unicode first.
ASCII defines 128 characters, which map to the numbers 0–127. Unicode defines (less than) 221 characters, which, similarly, map to numbers 0–221 (though not all numbers are currently assigned, and some are reserved). So, in short, Unicode is a superset of ASCII.
Reference: What's the difference between ASCII and Unicode?
Example
Using ASCII value and the value represented by a Unicode character is not same. For example.
System.out.println((int)'A'); // prints 65, ASCII value
System.out.println(Character.getNumericValue('A')); // prints 10 represents Unicode character 'A'
Now, if we look into your example, the difference will be clear.
String s = "Wasi";
for (Character c : s.toCharArray()) {
int val = c - 'a';
int val2 = Character.getNumericValue(c) - Character.getNumericValue('a');
System.out.println(val + " " + val2);
}
Output
-10 22
0 0
18 18
8 8
So, before judging which one is better, you should think which one actually you need.
One more important thing to note, Character.getNumericValue()
doesn't consider case (lower or upper) of a character.
For example, Character.getNumericValue('A')
and Character.getNumericValue('a')
, both returns the value 10.