If you want a lexicographic sort, just use String.compareTo(..). If that's not suitable, you could look at CharSet encodings and comparison using StringBuffer.