两个字符串看着相同 equals 比较不相同
public static String utf8Encode(String str) {
if (!isEmpty(str) && str.getBytes().length != str.length()) {
try {
return URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UnsupportedEncodingException occurred. ", e);
}
}
return str;
}
将两个字符串转换成utf-8格式 输出出来
有一个字符串前缀有%EF%BB%BF
刚开始以为是不同编码造成的 最后发现是
文字编码格式导致的 utf-8 分有bom 和无bom 带bom的前面包含%EF%BB%BF
解决方法
string.replace("\uFEFF", "");