java学习笔记34:Charactor的基本方法
发布日期:2021-05-07 02:03:22 浏览次数:27 分类:精选文章

本文共 6647 字,大约阅读时间需要 22 分钟。

Character类在Java平台上提供了丰富的方法来处理字符编码、转换、比较以及字符的编码点操作。这些方法主要用于处理字符的基本操作、编码点转换以及字符的各种属性判断。

1. 字符编码与转换

  • Character(char value):构造一个Character对象,表示指定char值的新分配对象。
  • charCount(int codePoint):确定char表示指定字符所需的值的数量(Unicode代码点)。
  • toChars(int codePoint):将指定字符(Unicode代码点)转换为存储在char数组中的UTF-16表示形式。
  • toChars(int codePoint, char[] dst, int dstIndex):将指定字符(Unicode代码点)转换为其UTF-16表示形式,指定目标数组和起始位置。

2. 字符属性判断

  • isAlphaabetic(int codePoint):确定指定的字符(Unicode代码点)是否为字母。
  • isBmpCodePoint(int codePoint):确定指定的字符(Unicode代码点)是否在基本多语言平面(BMP)中。
  • isCase敏感(int codePoint):确定指定的字符(Unicode代码点)是否为大写或小写字母。
  • isDefined(int codePoint):确定是使用Unicode中定义了字符(Unicode代码点)。
  • isDigit(int codePoint):确定指定的字符(Unicode代码点)是否为数字。
  • isHighSurrogate(int codePoint):返回表示UTF-16编码中指定的补充字符(Unicode代码点)的代理对的前导代理(高代理代码单元)。
  • isLowSurrogate(int codePoint):判断给定char值是Unicode低代理项代码单元(也称为尾部代理项代码单元)。
  • isSurrogatePair(char high, char low):确定指定的char值对是否是有效的Unicode代理项对。
  • isWhitespace(char ch):根据Java确定指定的字符是否为空白。

3. 字符编码操作

  • codePointAt(char[] a, int index):返回char数组给定索引处的代码点。
  • codePointAt(char[] a, int index, int limit):返回char数组给定索引处的代码点,其中只能使用索引index小于limit的数组元素。
  • codePointAt(CharSequence seq, int index):返回给定索引处的代码点CharSequence。
  • codePointBefore(char[] a, int index):返回给定char数组索引之前的代码点。
  • codePointBefore(char[] a, int index, int start):返回给定char数组索引之前的代码点,其中只能使用索引index大于或等于start的数组元素。
  • codePointBefore(CharSequence seq, int index):返回给定索引之前的代码点CharSequence。
  • codePointCount(char[] a, int offset, int count):返回char数组参数的子数组中的Unicode代码点数。
  • codePointCount(CharSequence seq, int beginIndex, int endIndex):返回指定char序列的文本范围内的Unicode代码点数。

4. 字符转换与比较

  • compareTo(Character anotherCharacter):用Character数字比较两个对象。
  • reverseBytes(char ch):返回通过反转指定char值中的字节顺序获得的值。

5. 字符编码点操作

  • toCodePoint(char high, char low):将指定的代理项对转换为其补充代码点值。
  • offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset):返回给定子char数组中与代码点给定index的偏移量的索引codePointOffset。
  • offsetByCodePoints(CharSequence seq, int index, int codePointOffset):返回给定char序列中与代码点给定index的偏移量的索引codePointOffset。

6. 字符转换操作

  • toLowerCase(char ch):使用UnicodeData文件中的大小写映射信息将字符参数转换为小写。
  • toLowerCase(int codePoint):使用UnicodeData文件中的大小写映射信息将字符(Unicode代码点)参数转换为小写。
  • toLowerCase(char c):返回String表示指定对象的对象char。
  • toTitleCase(char ch):使用UnicodeData文件中的大小写映射信息将字符参数转换为titlecase(转化为大小)。
  • toTitleCase(int codePoint):使用UnicodeData文件中的大小写映射信息将字符(Unicode代码点)参数转换为titlecase(转化为大小)。
  • toUpperCase(char ch):使用UnicodeData文件中的大小写映射信息将字符参数转换为大写。
  • toUpperCase(int codePoint):使用UnicodeData文件中的大小写映射信息将字符(Unicode代码点)参数转换为大写。

7. 字符名称与属性

  • getName(int codePoint):返回指定字符的Unicode名称,codePoint如果代码点为null,则返回 null unassigned。
  • getType(int codePoint):返回表示字符常规类别的值。
  • getNumericValue(int codePoint):返回指定的Unicode字符表示的int值。
  • getNumericValue(int codePoint):返回指定字符(Unicode代码点)表示的值int。
  • getType(char ch):返回表示字符常规类别的值。
  • getNumericValue(char ch):返回指定的Unicode字符表示的int值。

8. 字符方向性与镜像

  • getDirectionality(char ch):返回给定字符的Unicode方向性属性。
  • getDirectionality(int codePoint):返回给定字符的Unicode方向性属性(Unicode代码点)。
  • isMirrored(char ch):确定是否根据Unicode规范镜像该字符。
  • isMirrored(int codePoint):确定是否根据Unicode规范镜像指定的字符(Unicode代码点)。

9. 字符编码点与代理对

  • isBmpCodePoint(int codePoint):确定指定的字符(Unicode代码点)是否在基本多语言平面(BMP)中。
  • isSupplementaryCodePoint(int codePoint):确定指定的字符(Unicode代码点)是否在补充字符范围内。
  • isIdeographic(int codePoint):确定指定的字符(Unicode代码点)是否是Unicode标准定义的CJKV(中文,日文,韩文和越南文)表意文字。

10. 字符编码与转换

  • forDigit(int digit, int radix):确定指定计算机进制(radix)中特定数字的字符表示形式。
  • digit(int codePoint, int radix):返回指定基数中指定字符(Unicode代码点)的数值。
  • digit(char ch, int radix):返回ch指定基数中字符的数值。

11. 字符编码与代理对验证

  • isHighSurrogate(char ch):确定给定char值是否为 Unicode高代理代码单元(也称为前导代理代码单元)。
  • isLowSurrogate(char ch):确定给定char值是否为 Unicode低代理代码单元(也称为尾部代理代码单元)。
  • isSurrogatePair(char high, char low):确定指定的char值对是否是有效的Unicode代理项对。

12. 字符编码与转换验证

  • isValidCodePoint(int codePoint):确定指定的代码点是否是有效的Unicode代码点值。
  • isUnicodeIdentifierStart(int codePoint):确定是否允许将字符(Unicode代码点)作为Unicode标识符中的第一个字符。
  • isUnicodeIdentifierPart(int codePoint):确定指定的字符(Unicode代码点)是否可能是Unicode标识符的一部分,而不是第一个字符。
  • isJavaIdentifierStart(int codePoint):确定是否允许将字符(Unicode代码点)作为Java标识符中的第一个字符。
  • isJavaIdentifierPart(int codePoint):确定指定的字符(Unicode代码点)是否可能是Java标识符的一部分,而不是第一个字符。
  • isIdentifierIgnorable(char ch):确定指定的字符是否应被视为Java标识符或Unicode标识符中的可忽略字符。
  • isIdentifierIgnorable(int codePoint):确定指定的字符(Unicode代码点)是否应被视为Java标识符或Unicode标识符中的可忽略字符。

13. 字符编码与编码点操作

  • charCount(int codePoint):确定char表示指定字符所需的值的数量(Unicode代码点)。
  • codePointAt(char[] a, int index):返回char数组给定索引处的代码点。
  • codePointAt(char[] a, int index, int limit):返回char数组给定索引处的代码点,其中只能使用索引index小于limit的数组元素。
  • codePointAt(CharSequence seq, int index):返回给定索引处的代码点CharSequence。
  • codePointBefore(char[] a, int index):返回给定char数组索引之前的代码点。
  • codePointBefore(char[] a, int index, int start):返回给定char数组索引之前的代码点,其中只能使用索引index大于或等于start的数组元素。
  • codePointBefore(CharSequence seq, int index):返回给定索引之前的代码点CharSequence。
  • codePointCount(char[] a, int offset, int count):返回char数组参数的子数组中的Unicode代码点数。
  • codePointCount(CharSequence seq, int beginIndex, int endIndex):返回指定char序列的文本范围内的Unicode代码点数。

14. 字符编码与转换验证

  • isJavaIdentifierStart(char ch):确定指定的字符是否允许作为Java标识符中的第一个字符。
  • isJavaIdentifierStart(int codePoint):确定是否允许将字符(Unicode代码点)作为Java标识符中的第一个字符。
  • isJavaIdentifierPart(char ch):确定指定的字符是否可能是Java标识符的一部分,而不是第一个字符。
  • isJavaIdentifierPart(int codePoint):确定字符(Unicode代码点)是否可能是Java标识符的一部分,而不是第一个字符。
  • isIdentifierIgnorable(char ch):确定指定的字符是否应被视为Java标识符或Unicode标识符中的可忽略字符。
  • isIdentifierIgnorable(int codePoint):确定指定的字符(Unicode代码点)是否应被视为Java标识符或Unicode标识符中的可忽略字符。

15. 字符编码与转换操作

  • reverseBytes(char ch):返回通过反转指定char值中的字节顺序获得的值。
  • toCodePoint(char high, char low):将指定的代理项对转换为其补充代码点值。

16. 字符编码与转换验证

  • isHighSurrogate(char ch):确定给定char值是否为 Unicode高代理代码单元(也称为前导代理代码单元)。
  • isLowSurrogate(char ch):确定给定char值是否为 Unicode低代理代码单元(也称为尾部代理代码单元)。
  • isSurrogatePair(char high, char low):确定指定的char值对是否是有效的Unicode代理项对。

17. 字符编码与转换操作

  • toCodePoint(char high, char low):将指定的代理项对转换为其补充代码点值。
  • offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset):返回给定子char数组中与代码点给定index的偏移量的索引codePointOffset。
  • offsetByCodePoints(CharSequence seq, int index, int codePointOffset):返回给定char序列中与代码点给定index的偏移量的索引codePointOffset。

18. 字符编码与转换验证

  • isBmpCodePoint(int codePoint):确定指定的字符(Unicode代码点)是否在基本多语言平面(BMP)中。
  • isSupplementaryCodePoint(int codePoint):确定指定的字符(Unicode代码点)是否在补充字符范围内。
  • isIdeographic(int codePoint):确定指定的字符(Unicode代码点)是否是Unicode标准定义的CJKV(中文,日文,韩文和越南文)表意文字。

19. 字符编码与转换操作

  • forDigit(int digit, int radix):确定指定计算机进制(radix)中特定数字的字符表示形式。
  • digit(int codePoint, int radix):返回指定基数中指定字符(Unicode代码点)的数值。
  • digit(char ch, int radix):返回ch指定基数中字符的数值。

20. 字符编码与转换验证

  • isMirrored(char ch):确定是否根据Unicode规范镜像该字符。
  • isMirrored(int codePoint):确定是否根据Unicode规范镜像指定的字符(Unicode代码点)。

21. 字符编码与转换操作

  • reverseBytes(char ch):返回通过反转指定char值中的字节顺序获得的值。

Character类为Java开发者提供了一个强大的工具来处理字符的各种操作,从基本的字符转换到复杂的编码点操作,涵盖了开发中常用的各种场景。通过这些方法,开发者可以高效地处理字符数据,确保代码的正确性和性能。

上一篇:java学习笔记35:Short的基本方法
下一篇:java学习笔记33:Byte的基本方法

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月12日 05时16分31秒