Why Java Character.toUpperCase/toLowerCase has no Locale parameter like String.toUpperCase/toLowerCase

社会主义新天地 提交于 2019-12-05 01:24:34

From the Character#toUpperCase(int) Javadoc,

In general, String.toUpperCase() should be used to map characters to uppercase. String case mapping methods have several benefits over Character case mapping methods. String case mapping methods can perform locale-sensitive mappings, context-sensitive mappings, and 1:M character mappings, whereas the Character case mapping methods cannot.

So, the answer is your second example (String.toUpperCase)

As the Javadoc says:

In general, String.toUpperCase() should be used to map characters to uppercase. String case mapping methods have several benefits over Character case mapping methods. String case mapping methods can perform locale-sensitive mappings, context-sensitive mappings, and 1:M character mappings, whereas the Character case mapping methods cannot.

So use String.toUppercase()

Dawood says reinstate Monica

If the question is "which method should I use", then this question is a duplicate of String conversion to Title Case and the correct answer is EITHER

If the question is "why doesn't Character have locale-sensitive case-changing methods", then the only way you're likely to get an answer is to consult one of the designers of the Java language. It's unlikely that the Stack Overflow community will be able to give you the answer you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!