考虑这个程序:
import java.util.regex.Pattern;
public class xx {
/*
* Ñ
* LATIN CAPITAL LETTER N WITH TILDE
* Unicode: U+00D1, UTF-8: C3 91
*/
public static final String BIG_N = "\u00d1";
/*
* ñ
* LATIN SMALL LETTER N WITH TILDE
* Unicode: U+00F1, UTF-8: C3 B1
*/
public static final String LITTLE_N = "\u00f1";
public static void main(String[] args) throws Exception {
System.out.println(BIG_N.equalsIgnoreCase(LITTLE_N));
System.out.println(Pattern.compile(BIG_N, Pattern.CASE_INSENSITIVE).matcher(LITTLE_N).matches());
}
}
由于 Ñ 是 ñ 的大写版本,您会期望它打印:
true
true
但它实际打印的(java 1.7.0_17-b02)是:
true
false
为什么?