In JavaScript, .charCodeAt()
returns a Unicode value at a certain point in the string which you pass to a function. If I only had one character, I could use the code below to get the Unicode value in Java.
public int charCodeAt(char c) {
int x;
return x = (int) c;
}
If I had a string in Java, how would I get the Unicode value of one individual character within the string, like the .charCodeAt()
function does for JavaScript?
Java has the same method: Character.codePointAt(CharSequence seq, int index);
String str = "Hello World";
int codePointAt0 = Character.codePointAt(str, 0);