I’d like to know what is the last char that exists in java?
I have a program which deals with words ordered in lexicography, I just wanna make sure at most that a certain word would be last this is why I wanna know what char should it be?
edited: I don’t mean the last char from string.
More simply, I’d like to know what should be the first char in a string that I’d like to be considered as last in lexic order – notice: when I use string.compareTo method?
If you are talking about simple
charvalues, then the answer is'\uffff'. (Javacharvalues are really just signed 16-bit integers, and'\uffff'or65535is the largest integer representable by that type. The\uis Java’s Unicode escape syntax.)However, that ignores the fact that a single Java
charinstance can only represent Unicode codepoints that falls within Unicode plane 0 (the BMP). The standard currently defines planes 0 through 16. Code points in the higher planes are represented as pairs of Javacharvalues; they are called surrogate pairs.You will need to decide if your application needs to deal with surrogate pairs. (It depends whether you want to support text that uses “esoteric” characters in the higher Unicode planes.) If it does, then you won’t be able to use the standard
String.compareTomethod and the like. I recommend that you take a look at the ICU libraries.