jdk源码解析--基本数据类型
Posted 我的IT技术路
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jdk源码解析--基本数据类型相关的知识,希望对你有一定的参考价值。
在Java语言中,有八个基本数据,他们分别是short,int,long,bool,byte,char,double,float,大致分为整数,符号,小数,逻辑这几类。整型的有short(短整型2字节,16位),int(4字节),long(8字节)。符号型有byte(字节)和char(字符)。小数有float(单精度,4字节),double(双精度8字节)。与之对应的包装类有
Short,Integer,Long,Boolen,Byte,Character,Double,Float。基本数据类型的默认值不是null,但是其对应的包装类对应的默认值为null。关于基本数据类型对应的包装类jdk源码分析如下:
一、Boolean类
1.1 Boolean类是一个逻辑类,对应的基本类型关键字是boolean。如下为具体该类的结构。
1. public final class Boolean implements java.io.Serializable,
2. Comparable<Boolean>{
3. public static final Boolean TRUE = new Boolean(true);//定义true
4. public static final Boolean FALSE = new Boolean(false);//定义false
5. @SuppressWarnings("unchecked")
6. public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");//类型
7. private final boolean value;//存入boolean值
8. }
1.2 构造函数
1. public Boolean(boolean value) {
2. this.value = value;
3. }
4. public Boolean(String s) {
5. this(parseBoolean(s));
6. }
7. public static boolean parseBoolean(String s) {
8. return ((s != null) && s.equalsIgnoreCase("true"));//判断是否是true字符串
9. }
1.3 成员函数:基本都比较简单
1.3.1 Valueof
1. public static Boolean valueOf(boolean b) {
2. return (b ? TRUE : FALSE); //返回这个Boolean的类
3. }
1.3.2 toString
1. public static String toString(boolean b) {
2. return b ? "true" : "false";
3. }
1.3.3 hashCode
1. public static int hashCode(boolean value) {
2. return value ? 1231 : 1237;
3. }
1.3.4 Equals
1. public boolean equals(Object obj) {
2. if (obj instanceof Boolean) {
3. return value == ((Boolean)obj).booleanValue();
4. }
5. return false;
6. }
1.3.5 通过系统变量获取bool值
1. public static boolean getBoolean(String name) {
2. boolean result = false;
3. try {
4. result = parseBoolean(System.getProperty(name))//获取系统变量的值
5. } catch (IllegalArgumentException | NullPointerException e) {
6. }
7. return result;
8. }
1.3.6 比较
1. public static int compare(boolean x, boolean y) {
2. return (x == y) ? 0 : (x ? 1 : -1);
3. }
1.3.7 逻辑与/或/异或
1. public static boolean logicalAnd(boolean a, boolean b) {
2. return a && b;
3. }
4. public static boolean logicalOr(boolean a, boolean b) {
5. return a || b;
6. }
7. public static boolean logicalXor(boolean a, boolean b) {
8. return a ^ b;
9. }
二、Byte类
2.1 Byte类是一个基本的数据类型,基本上所有的数据类型底层都是通过byte和计算机进行交互。从成员函数看,byte可以看做是一个-128~127的整型,Byte的基本类定义如下:
1. public final class Byte extends Number implements Comparable<Byte> {
2. public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");//定义了基本类型
3. //开始定义好byte字节数组
4. private static class ByteCache {
5. private ByteCache(){}
6.
7. static final Byte cache[] = new Byte[-(-128) + 127 + 1];//定义了一个byte数组
8.
9. static {
10. for(int i = 0; i < cache.length; i++)
11. cache[i] = new Byte((byte)(i - 128));//实例化byte数组
12. }
13. }
14. private final byte value;//具体的数据存入,常量
15. }
2.2 构造函数:
1. public Byte(String s) throws NumberFormatException {
2. this.value = parseByte(s, 10);
3. }
4. public Byte(byte value) {
5. this.value = value;
6. }
2.3 成员函数:
toString:
1. public static String toString(byte b) {
2. return Integer.toString((int)b, 10);
3. }
Valueof:
1. public static Byte valueOf(byte b) {
2. final int offset = 128;
3. return ByteCache.cache[(int)b + offset];
4. }
parseByte:
1. public static Byte valueOf(byte b) {
2. final int offset = 128;
3. return ByteCache.cache[(int)b + offset];
4. }
Decode:解码,转化为对应的整型
1. public static Byte decode(String nm) throws NumberFormatException {
2. int i = Integer.decode(nm);
3. if (i < MIN_VALUE || i > MAX_VALUE)
4. throw new NumberFormatException(
5. "Value " + i + " out of range from input " + nm);
6. return valueOf((byte)i);
7. }
HashCode:
1. public static int hashCode(byte value) {
2. return (int)value;
3. }
Equals:
1. public boolean equals(Object obj) {
2. if (obj instanceof Byte) {
3. return value == ((Byte)obj).byteValue();
4. }
5. return false;
6. }
比较:
1. public int compareTo(Byte anotherByte) {
2. return compare(this.value, anotherByte.value);
3. }
4. public static int compare(byte x, byte y) {
5. return x - y;
6. }
三、Double类
3.1 Double类是双精度的浮点型,相比于等下要介绍的单精度浮点型准确度要更高。看下其基本类的结构:
1. public final class Double extends Number implements Comparable<Double> {
2. //正数
3. public static final double POSITIVE_INFINITY = 1.0 / 0.0;
4.
5. //负数
6. public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
7. //0
8. public static final double NaN = 0.0d / 0.0;
9.
10. //最大值
11. public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
12.
13. //小数点前面为1
14. public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
15.
16. //小数点前面是0
17. public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
18. //最大指数
19. public static final int MAX_EXPONENT = 1023;
20. //最小指数
21. public static final int MIN_EXPONENT = -1022;
22. //占位的大小
23. public static final int SIZE = 64;
24. //占用的位置
25. public static final int BYTES = SIZE / Byte.SIZE;
26. //类型
27. public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
28. private final double value;//存值的地方
29. }
3.2 构造函数
1. public Double(double value) {
2. this.value = value;
3. }
4. public Double(String s) throws NumberFormatException {
5. value = parseDouble(s);
6. }
3.3 成员函数
1. public static String toHexString(double d) {
2.
3. if (!isFinite(d) )
4. // 对于无穷的和非数字直接使用str返回
5. return Double.toString(d);
6. else {
7. // 初始化最大输出位置
8. StringBuilder answer = new StringBuilder(24);
9.
10. if (Math.copySign(1.0, d) == -1.0) //负数
11. answer.append("-");
12.
13. answer.append("0x");//16进制
14.
15. d = Math.abs(d);//正数
16.
17. if(d == 0.0) {
18. answer.append("0.0p0");//如果是0直接返回
19. } else {
20. boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
21.
22. //
23. long signifBits = (Double.doubleToLongBits(d)
24. & DoubleConsts.SIGNIF_BIT_MASK) |
25. 0x1000000000000000L;
26.
27.
28. answer.append(subnormal ? "0." : "1.");
29.
30. // 转换为16进制
31. String signif = Long.toHexString(signifBits).substring(3,16);
32. answer.append(signif.equals("0000000000000") ? // 13 zeros
33. "0":
34. signif.replaceFirst("0{1,12}$", ""));
35.
36. answer.append('p');
37. // 算出指数的数值
38. answer.append(subnormal ?
39. DoubleConsts.MIN_EXPONENT:
40. Math.getExponent(d));
41. }
42. return answer.toString();
43. }
44. }
是否是数字:
1. public static boolean isNaN(double v) {
2. return (v != v);
3. }
是否无穷:
1. public static boolean isInfinite(double v) {
2. return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
3. }
Hashcode equals:
1. public static int hashCode(double value) {
2. long bits = doubleToLongBits(value);
3. return (int)(bits ^ (bits >>> 32));
4. }
5. public boolean equals(Object obj) {
6. return (obj instanceof Double)
7. && (doubleToLongBits(((Double)obj).value) ==
8. doubleToLongBits(value));
9. }
DoubleToLongBits:
1. public static long doubleToLongBits(double value) {
2. long result = doubleToRawLongBits(value);
3. // Check for NaN based on values of bit fields, maximum
4. // exponent and nonzero significand.
5. if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
6. DoubleConsts.EXP_BIT_MASK) &&
7. (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
8. result = 0x7ff8000000000000L;
9. return result;
10. }
11. public static native long doubleToRawLongBits(double value);//通过计算器字节结算的
四、Float 类
4.1 类似于Double类的双精度,单精度浮点型Float在源码的实现上基本类似。toHexString是基于双精度Double实现的,其他的方法实现基本类似。如下为转化为16进制Str类型的方法:
1. public static String toHexString(float f) {
2. if (Math.abs(f) < FloatConsts.MIN_NORMAL
3. && f != 0.0f ) {// float subnormal
4. //通过double类型的进行转换
5. String s = Double.toHexString(Math.scalb((double)f,
6. /* -1022+126 */
7. DoubleConsts.MIN_EXPONENT-
8. FloatConsts.MIN_EXPONENT));
9.
10. return s.replaceFirst("p-1022$", "p-126");
11. }
12. else // double string will be the same as float string
13. return Double.toHexString(f);
14. }
五、Integer 类
5.1 整型int对应的包装类Integer,在这个类中,提供了较多进制转换,整型字符串转换的方法。在平时使用较多,看下底层的实现。类的定义和构造函数如下:
1. public final class Integer extends Number implements Comparable<Integer> {
2. private final int value;
3. public Integer(int value) {//提供了整型到包装
4. this.value = value;
5. }
6. public Integer(String s) throws NumberFormatException {//提供了字符串到整型的转换
7. this.value = parseInt(s, 10);
8. }
5.2 重要方法:
转换为相应进制的字符串:
1. public static String toString(int i, int radix) {//输入数值,需要转换的进制
2. if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)//进制判断
3. radix = 10;
4.
5. /* Use the faster version */
6. if (radix == 10) {
7. return toString(i);//直接转
8. }
9.
10. char buf[] = new char[33];
11. boolean negative = (i < 0);
12. int charPos = 32;
13.
14. if (!negative) {
15. i = -i;
16. }
17.
18. while (i <= -radix) {
19. buf[charPos--] = digits[-(i % radix)];//一直求余赋值
20. i = i / radix;
21. }
22. buf[charPos] = digits[-i];
23.
24. if (negative) {
25. buf[--charPos] = '-';
26. }
27.
28. return new String(buf, charPos, (33 - charPos));
29. }
30. public static String toString(int i) {
31. if (i == Integer.MIN_VALUE)
32. return "-2147483648";
33. int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
34. char[] buf = new char[size];
35. getChars(i, size, buf);
36. return new String(buf, true);
37. }
38. //计算转化为string的长度
39. static int stringSize(int x) {
40. for (int i=0; ; i++)
41. if (x <= sizeTable[i])//sizeTable是一个某个长度下的最大整型值
42. return i+1;
43. }
44. final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
45. 99999999, 999999999, Integer.MAX_VALUE };
46.
47. static void getChars(int i, int index, char[] buf) {//输入整数值,长度,输出的位置
48. int q, r;
49. int charPos = index;
50. char sign = 0;
51.
52. if (i < 0) {
53. sign = '-';
54. i = -i;
55. }
56.
57. // 每次产生两位字符位置的值,直到i<65536
58. while (i >= 65536) {
59. q = i / 100;
60. // r = i - (q * 100);
61. r = i - ((q << 6) + (q << 5) + (q << 2));
62. i = q;
63. buf [--charPos] = DigitOnes[r];//计算个位
64. buf [--charPos] = DigitTens[r];//计算十位
65. }
66.
67. // Fall thru to fast mode for smaller numbers
68. // assert(i <= 65536, i);
69. for (;;) {
70. q = (i * 52429) >>> (16+3);
71. r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ,依次计算
72. buf [--charPos] = digits [r];//赋值
73. i = q;
74. if (i == 0) break;
75. }
76. if (sign != 0) {
77. buf [--charPos] = sign;//加上符号
78. }
79. }
转16进制str:
1. public static String toHexString(int i) {
2. return toUnsignedString0(i, 4);
3. }
4. private static String toUnsignedString0(int val, int shift) {
5. // assert shift > 0 && shift <=5 : "Illegal shift value";
6. int mag = Integer.SIZE - Integer.numberOfLeadingZeros(val);
7. int chars = Math.max(((mag + (shift - 1)) / shift), 1);//计算需要字符长度的个数
8. char[] buf = new char[chars];
9.
10. formatUnsignedInt(val, shift, buf, 0, chars);
11.
12. // Use special constructor which takes over "buf".
13. return new String(buf, true);
14. }
15. //返回无符号整型最高位非0的前面0的个数
16. public static int numberOfLeadingZeros(int i) {
17. // HD, Figure 5-6
18. if (i == 0)
19. return 32;
20. int n = 1;
21. if (i >>> 16 == 0) { n += 16; i <<= 16; }
22. if (i >>> 24 == 0) { n += 8; i <<= 8; }
23. if (i >>> 28 == 0) { n += 4; i <<= 4; }
24. if (i >>> 30 == 0) { n += 2; i <<= 2; }
25. n -= i >>> 31;
26. return n;
27. }
28. //
29. static int formatUnsignedInt(int val, int shift, char[] buf, int offset, int len) {
30. int charPos = len;
31. int radix = 1 << shift;
32. int mask = radix - 1;
33. do {
34. buf[offset + --charPos] = Integer.digits[val & mask];//通过位与实现
35. val >>>= shift;
36. } while (val != 0 && charPos > 0);
37.
38. return charPos;
39. }
Str转换为Integer:
1. public static int parseInt(String s, int radix)
2. throws NumberFormatException
3. {
4.
5.
6. if (s == null) {
7. throw new NumberFormatException("null");
8. }
9.
10. if (radix < Character.MIN_RADIX) {
11. throw new NumberFormatException("radix " + radix +
12. " less than Character.MIN_RADIX");
13. }
14.
15. if (radix > Character.MAX_RADIX) {
16. throw new NumberFormatException("radix " + radix +
17. " greater than Character.MAX_RADIX");
18. }
19. //以上异常判断
20. int result = 0;
21. boolean negative = false;
22. int i = 0, len = s.length();
23. int limit = -Integer.MAX_VALUE;
24. int multmin;
25. int digit;
26.
27. if (len > 0) {
28. char firstChar = s.charAt(0);
29. if (firstChar < '0') { // 可能是符号 + -
30. if (firstChar == '-') {
31. negative = true;
32. limit = Integer.MIN_VALUE;
33. } else if (firstChar != '+')
34. throw NumberFormatException.forInputString(s);
35.
36. if (len == 1) // Cannot have lone "+" or "-"
37. throw NumberFormatException.forInputString(s);
38. i++;
39. }
40. multmin = limit / radix;
41. while (i < len) {
42. // 使用负方向,避免整数累加的极限值取不到
43. digit = Character.digit(s.charAt(i++),radix);
44. if (digit < 0) {
45. throw NumberFormatException.forInputString(s);
46. }
47. if (result < multmin) {
48. throw NumberFormatException.forInputString(s);
49. }
50. result *= radix;//该位*转换率
51. if (result < limit + digit) {
52. throw NumberFormatException.forInputString(s);
53. }
54. result -= digit;//进行做差
55. }
56. } else {
57. throw NumberFormatException.forInputString(s);
58. }
59. return negative ? result : -result;//加上符号位
60. }
Str转无符号整型:
1. public static int parseUnsignedInt(String s, int radix)
2. throws NumberFormatException {
3. if (s == null) {
4. throw new NumberFormatException("null");
5. }
6.
7. int len = s.length();
8. if (len > 0) {
9. char firstChar = s.charAt(0);
10. if (firstChar == '-') {
11. throw new
12. NumberFormatException(String.format("Illegal leading minus sign " +
13. "on unsigned string %s.", s));
14. } else {
15. if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
16. (radix == 10 && len <= 9) ) { // Integer.MAX_VALUE in base 10 is 10 digits
17. return parseInt(s, radix);
18. } else {
19. long ell = Long.parseLong(s, radix);//核心在使用Long进行转换
20. if ((ell & 0xffff_ffff_0000_0000L) == 0) {
21. return (int) ell;
22. } else {
23. throw new
24. NumberFormatException(String.format("String value %s exceeds " +
25. "range of unsigned int.", s));
26. }
27. }
28. }
29. } else {
30. throw NumberFormatException.forInputString(s);
31. }
32. }
解码:
1. public static Integer decode(String nm) throws NumberFormatException {
2. int radix = 10;
3. int index = 0;
4. boolean negative = false;
5. Integer result;
6.
7. if (nm.length() == 0)
8. throw new NumberFormatException("Zero length string");
9. char firstChar = nm.charAt(0);
10. // Handle sign, if present
11. if (firstChar == '-') {//根据第一个字符判断是哪种类型的数据,进行相应的转码
12. negative = true;
13. index++;
14. } else if (firstChar == '+')
15. index++;
16.
17. // Handle radix specifier, if present
18. if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
19. index += 2;
20. radix = 16;
21. }
22. else if (nm.startsWith("#", index)) {
23. index ++;
24. radix = 16;
25. }
26. else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
27. index ++;
28. radix = 8;
29. }
30.
31. if (nm.startsWith("-", index) || nm.startsWith("+", index))
32. throw new NumberFormatException("Sign character in wrong position");
33.
34. try {
35. result = Integer.valueOf(nm.substring(index), radix);
36. result = negative ? Integer.valueOf(-result.intValue()) : result;
37. } catch (NumberFormatException e) {
38. // If number is Integer.MIN_VALUE, we'll end up here. The next line
39. // handles this case, and causes any genuine format error to be
40. // rethrown.
41. String constant = negative ? ("-" + nm.substring(index))
42. : nm.substring(index);
43. result = Integer.valueOf(constant, radix);
44. }
45. return result;
46. }
整型类中还包含一些位操作的函数,在实际中使用的频率不多,基本都要理解int类型总共32位,然后进行相应的位运算,位运算的好处是效率快,性能高。如下表为具体的函数及其作用:
函数名 |
作用 |
int highestOneBit(int i) |
整数最高位为1的位置对应的整数值 |
int lowestOneBit(int i) |
整数最低位为1的位置对应的整数值 |
int numberOfLeadingZeros(int i) |
整数最高位1前面还有多少个0(4字节) |
int numberOfTrailingZeros(int i) |
整数最低位1后面还有多少个0 |
int bitCount(int i) |
整数中1的个数 |
Int rotateLeft(int i, int distance) |
右移 |
int rotateRight(int i, int distance) |
左移 |
int reverse(int i) |
按位反转 |
int signum(int i) |
整数的符号位 |
int reverseBytes(int i) |
按照字节反转 |
Long 类和Short 类基本和Integer类似,具体可以参照Integer类型。
六、Character 类
6.1 字符类是使用较多的一类,常用的String类底层就是一个字符串数组。字符类包含较多内容,不同的字符涉及到不同的字节位数。引用Java编程的逻辑里面一段对Unicode的描述:
“Unicode给世界上每个字符分配了一个编号,编号范围从0x000000到0x10FFFF。编号范围在0x0000到0xFFFF之间的字符,为常用字符集,称BMP(Basic Multilingual Plane)字符。编号范围在0x10000到0x10FFFF之间的字符叫做增补字符(supplementary character)。Unicode主要规定了编号,但没有规定如何把编号映射为二进制,UTF-16是一种编码方式,或者叫映射方式,它将编号映射为两个或四个字节,对BMP字符,它直接用两个字节表示,对于增补字符,使用四个字节,前两个字节叫高代理项(high surrogate),范围从0xD800到0xDBFF,后两个字节叫低代理项(low surrogate),范围从0xDC00到0xDFFF,UTF-16定义了一个公式,可以将编号与四字节表示进行相互转换。Java内部采用UTF-16编码,char表示一个字符,但只能表示BMP中的字符,对于增补字符,需要使用两个char表示,一个表示高代理项,一个表示低代理项。使用int可以表示任意一个Unicode字符,低21位表示Unicode编号,高11位设为0。整数编号在Unicode中一般称为代码点(Code Point),表示一个Unicode字符,与之相对,还有一个词代码单元(Code Unit)表示一个char。”有了对字符的基本了解,下面看下字符类的基本结构。
1. public final class Character implements java.io.Serializable, Comparable<Character> {
2. private final char value; //定义一个final类型的成员变量
3. private static class CharacterCache {
4. private CharacterCache(){}
5.
6. static final Character cache[] = new Character[127 + 1];
7.
8. static {
9. for (int i = 0; i < cache.length; i++)
10. cache[i] = new Character((char)i);//定义好128个整数对应字符
11. }
12. }
13. }
6.2 构造函数
1. public Character(char value) {
2. this.value = value;
3. }
6.3 常用的方法
Hashcode/equals:
1. public static int hashCode(char value) {
2. return (int)value;
3. }
1. public boolean equals(Object obj) {
2. if (obj instanceof Character) {
3. return value == ((Character)obj).charValue();
4. }
5. return false;
6. }
判读字符编码类型:
1. public static boolean isValidCodePoint(int codePoint) {
2. // Optimized form of:
3. // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
4. int plane = codePoint >>> 16;
5. return plane < ((MAX_CODE_POINT + 1) >>> 16);
6. }
7. public static boolean isBmpCodePoint(int codePoint) {
8. return codePoint >>> 16 == 0;
9. // Optimized form of:
10. // codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
11. // We consistently use logical shift (>>>) to facilitate
12. // additional runtime optimizations.
13. }
14. public static boolean isSupplementaryCodePoint(int codePoint) {
15. return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
16. && codePoint < MAX_CODE_POINT + 1;
17. }
特定字符判断:
1. public static boolean isLowerCase(int codePoint) {
2. return getType(codePoint) == Character.LOWERCASE_LETTER ||
3. CharacterData.of(codePoint).isOtherLowercase(codePoint);
4. }
5. public static boolean isUpperCase(int codePoint) {
6. return getType(codePoint) == Character.UPPERCASE_LETTER ||
7. CharacterData.of(codePoint).isOtherUppercase(codePoint);
8. }
9. //标题首字母
10. public static boolean isTitleCase(int codePoint) {
11. return getType(codePoint) == Character.TITLECASE_LETTER;
12. }
13. //是否是 数字
14. public static boolean isDigit(int codePoint) {
15. return getType(codePoint) == Character.DECIMAL_DIGIT_NUMBER;
16. }
17. //是否是Unicode定义的字符
18. public static boolean isDefined(int codePoint) {
19. return getType(codePoint) != Character.UNASSIGNED;
20. }
21. //是否是英文字符
22. public static boolean isLetter(int codePoint) {
23. return ((((1 << Character.UPPERCASE_LETTER) |
24. (1 << Character.LOWERCASE_LETTER) |
25. (1 << Character.TITLECASE_LETTER) |
26. (1 << Character.MODIFIER_LETTER) |
27. (1 << Character.OTHER_LETTER)) >> getType(codePoint)) & 1)
28. != 0;
29. }
字符转换:
1. public static int toLowerCase(int codePoint) {
2. return CharacterData.of(codePoint).toLowerCase(codePoint);
3. }
4. public static int toUpperCase(int codePoint) {
5. return CharacterData.of(codePoint).toUpperCase(codePoint);
6. }
7. public static int toTitleCase(int codePoint) {
8. return CharacterData.of(codePoint).toTitleCase(codePoint);
9. }
10. public static int digit(int codePoint, int radix) {
11. return CharacterData.of(codePoint).digit(codePoint, radix);
12. }
除了上面介绍的一些常用方法,字符还有一些其他的方法,获取字符属性,获取编码名称等方法。Java在实现字符类的同时,有相应的辅助类:字符数据类系列:CharacterData,字符名称CharacterName。
以上是关于jdk源码解析--基本数据类型的主要内容,如果未能解决你的问题,请参考以下文章
CopyOnWriteArrayList源码解析(基于JDK8)