Java 8新特性 - (12)无符号运算
Java 8新特性 - (12)无符号运算
June 8, 2021
Java 8为整型包装类,增加类支持无符号运算的方法。注意:仅仅是在新增的运算方法中将long或者int当做无符号的数做运算,而本身java并不支持无符号的数据类型
Java 8为Integer,Long新增如下方法:
// 该方法将指定int货long型整数转换为无符号整数对应的字符串
static String toUnsignedString(int/long i)
// 该方法将指定int或long型整数转换为指定进制的无符号整数对应的字符串
static String toUnsignedString(int i/long,int radix)
// 该方法将指定字符串解析成无符号整数。当调用类为Integer时,xxx代表int;当调用类是Long时,xxx代表long
static xxx parseUnsignedXxx(String s)
// 该方法将指定字符串按指定进制解析成无符号整数。当调用类为Integer时,xxx代表int;当调用是Long时,xxx代表long
static xxx parseUnsignedXxx(String s,int radix)
// 该方法将x,y两个整数转换为无符号整数后比较大小。当调用类为Integer时,xxx代表int;当调用类是Long时,xxx代表long
static int compareUnsigned(xxx x,xxx y)
// 该方法将x、y两个整数转换为无符号整数后计算他们相除的商。当调用类为Integer时,xxx代表int;当调用类是Long时,xxx代表long
static long divideUnsigned(long dividend,long divisor)
// 该方法将x、y两个整数转换为无符号整数后计算他们相除的余数。当调用类为Integer是,xxx代表int;当调用类是Long时,xxx代表long
static long remainderUnsigned(long dividend,long divisor)
java 8还为Byte、Short增加了toUnsignedInt(xxx x) utoUnsignedLong(yyy x)两个方法,这两个方法用于将指定byte或short类型的变量或值转换成无符号的int或long值
参考:
最后更新于