介绍一下新增的几个函数和变量,主要分析源码,用法请参考官方文档
1、几个跟无符号整数有关的函数
1.8中真的增加了很多个跟无符号有关的函数。。
1.1 public static String toUnsignedString(int i, int radix)
返回一个无符号的数字字符串表示,复用了Long的同名方法。具体实现等写到Long类的时候写。radix给定了进制
public static String toUnsignedString(int i),默认进制为十进制
1.2 public static int parseUnsignedInt(String s, int radix)
将给定字符串转换为无符号整型数,用参数radix给定基数(即进制)
public static int parseUnsignedInt(String s)默认进制为十进制
以下为parseUnsignedInt的源码以及相关注释、说明:
/**
* 前面很长一串的介绍就省略了哈。。。
* 字符串参数s只允许有‘+’和对应进制的数字。
*
* @throws NumberFormatException if the {@code String}
* does not contain a parsable {@code int}.
* 当这个字符串参数不存在可以被转换(映射)的整型数字,则抛出NumberFormatException异常
* @since 1.8
*/
public static int parseUnsignedInt(String s, int radix)
throws NumberFormatException {
if (s == null) {
throw new NumberFormatException("null");
}
int len = s.length();
if (len > 0) {
char firstChar = s.charAt(0