String 与 char 互转
对String里的char进行处理过滤再转回String
考虑了大于char表示范围的符号
char 2个byte,有的字符会占3、4或者更多byte。
https://stackoverflow.com/questions/31977356/using-streams-to-manipulate-a-string
StringBuilder sb = ... ;
string.codePoints()
.filter(...)
.forEachOrdered(sb::appendCodePoint);
return sb.toString();对于字母
private Object encode1(String str) {
StringBuilder sb = new StringBuilder("");
str.chars().sorted().map(c -> (char)c).forEach(sb::appendCodePoint);
return sb.toString();
}Last updated
Was this helpful?