Java Character toTitleCase() 方法

2024年11月6日 | 阅读 4 分钟

Character 类的 toTitleCase(char ch) 方法使用 Unicode 数据文件中提供的映射信息,将给定的字符参数转换为标题形式。应注意,对于某些字符,Character.isTitleCase(Character.TitleCase(ch)) 可能不总是返回 true。

可以看到,如果一个字符没有明确的标题大小写映射,并且根据 Unicode 数据文件它不是一个标题大小写字符,那么将返回其大写映射。另一方面,如果字符参数已经是标题大小写字符,则将返回相同的值。

语法

参数

ch:需要转换的字符。

返回值

toTitleCase(char ch) 方法返回给定字符的标题大小写形式。否则,该方法返回字符本身。

示例 1

输出

The titlecase of character 'b' is given as: B
The titlecase of character 'm' is given as: M

示例 2

输出

The titlecase of character ')' is given as: )
The titlecase of character 'G' is given as: G

Java Character toTitleCase()方法

Character 类的 toTitleCase(int codePoint) 方法使用 Unicode 数据文件中提供的映射信息,将给定的字符(Unicode 代码点)参数转换为标题形式。

应注意,对于某些字符,Character.isTitleCase(Character.TitleCase(codePoint)) 可能不总是返回 true。

可以看到,如果一个字符没有明确的标题大小写映射,并且根据 Unicode 数据文件它不是一个标题大小写字符,那么将返回其大写映射。另一方面,如果字符参数已经是标题大小写字符,则将返回相同的值。

语法

参数

codePoint:需要测试的字符的 codePoint。

返回值

toTitleCase(int codePoint) 方法返回给定字符(Unicode 代码点)的标题大小写形式。否则,该方法返回字符本身。

示例 1

输出

The titlecase for the character '153' isgiven as: 153
The titlecase for the character '128' isgiven as: 128

示例 2

输出

The titlecase for the character '273' isgiven as: 272
The titlecase for the character '156' isgiven as: 156