Locale ROOT Case Mapping Turkish I Pitfall
Turkish uppercases i to dotted İ: use Locale.ROOT or equalsIgnoreCase for keys and protocol tokens, never the machine default locale.
Code
import java.util.Locale;
public class LocaleCaseMapping {
public static void main(String[] args) {
// 土耳其语区:i 的大写不是 I 而是 İ,I 的小写不是 i 而是 ı
Locale turkish = Locale.forLanguageTag("tr");
System.out.println("tr toUpper: " + "file".toUpperCase(turkish));
System.out.println("tr toLower: " + "FILE".toLowerCase(turkish));
// Locale.ROOT 与环境无关:协议键名、持久化标识符归一化用它
System.out.println("root toUpper: " + "file".toUpperCase(Locale.ROOT));
System.out.println("root toLower: " + "FILE".toLowerCase(Locale.ROOT));
// 无参版本跟随默认 locale:换台机器结果可能不同
System.out.println("default toUpper: " + "file".toUpperCase());
// 大小写无关比对也可以完全绕开大小写映射
System.out.println("match: " + "CONTENT-TYPE".equalsIgnoreCase("content-type"));
}
}Inside the snippet
Count the class LocaleCaseMapping and the function main as the entire surface area of Locale ROOT Case Mapping Turkish I Pitfall.
Using it
Running the file prints labeled results such as tr toUpper:, tr toLower:, root toUpper: — each operation’s effect is visible in the output.
Key statements
Locale turkish = Locale.forLanguageTag("tr");
Interactive Tools for This Topic
Case ConverterConvert text between lowercase, uppercase, title, sentence, camelCase, snake_case, and kebab-case while preserving Unicode letters and numbers.Number FormatterFormat numbers with thousands grouping, fixed decimals, custom separators, and an optional prefix or suffix.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does Locale ROOT Case Mapping Turkish I Pitfall print when run?
- The script runs standalone; its 6 labeled outputs include `tr toUpper:`, `tr toLower:`, `root toUpper:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.