public final class NumberUtils
extends java.lang.Object
NumberUtils
.| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends java.lang.Number> |
convert(java.lang.Number number,
java.lang.Class<T> targetClass)
转换数字对象到指定数字类型
.
|
static <N extends java.lang.Number> |
fillingAtStart(N number,
int minLength,
char sign)
传入数字长度低于传入最小长度则使用传入字符补全在开头使长度达到最小长度
.
|
static java.lang.Byte |
parse(java.lang.String target,
java.lang.Byte defaultValue)
将传入字符串转换为Byte,如果转换不了则返回传入的默认值
.
|
static <T extends java.lang.Number> |
parse(java.lang.String source,
java.lang.Class<T> toType)
将字符串转换为对应的类型,如果传入字符串是null或者空字符串,则返回null
.
|
static java.lang.Double |
parse(java.lang.String target,
java.lang.Double defaultValue)
将传入字符串转换为Double,如果转换不了则返回传入的默认值
.
|
static java.lang.Float |
parse(java.lang.String target,
java.lang.Float defaultValue)
将传入字符串转换为Float,如果转换不了则返回传入的默认值
.
|
static java.lang.Integer |
parse(java.lang.String target,
java.lang.Integer defaultValue)
将传入字符串转换为Integer,如果转换不了则返回传入的默认值
.
|
static java.lang.Long |
parse(java.lang.String target,
java.lang.Long defaultValue)
将传入字符串转换为Long,如果转换不了则返回传入的默认值
.
|
static java.math.BigInteger |
parse(java.lang.String numberStr,
Radix radix)
Parses the.
|
static java.math.BigInteger |
parse62Unit(java.lang.String numberStr)
Parses the 62 unit.
|
static int |
parse62UnitToInt(java.lang.String numberStr)
Parses the 62 unit to int.
|
static long |
parse62UnitToLong(java.lang.String numberStr)
Parses the 62 unit to long.
|
static java.math.BigInteger |
parse64Unit(java.lang.String numberStr)
Parses the 64 unit.
|
static int |
parse64UnitToInt(java.lang.String numberStr)
Parses the 64 unit to int.
|
static long |
parse64UnitToLong(java.lang.String numberStr)
Parses the 64 unit to long.
|
static byte[] |
toByteArray(int intSource)
将传入的int转换为长度为4的字节数组
.
|
static byte[] |
toByteArray(short shortSource)
将传入的short转换为长度为2的字节数组
.
|
static int |
toInt(byte[] bytes)
将传入的字节数组转换为int
.
|
static short |
toShort(byte[] bytes)
将传入的字节数组转换为short
.
|
static java.lang.String |
toString(java.math.BigInteger number,
Radix radix)
To string.
|
static java.lang.String |
toString(byte number,
Radix radix)
To string.
|
static java.lang.String |
toString(int number,
Radix radix)
To string.
|
static java.lang.String |
toString(long number,
Radix radix)
To string.
|
static java.lang.String |
toString(short number,
Radix radix)
To string.
|
static java.lang.String |
toString62Unit(java.math.BigInteger number)
To string 62 unit.
|
static java.lang.String |
toString62Unit(byte number)
To string 62 unit.
|
static java.lang.String |
toString62Unit(int number)
To string 62 unit.
|
static java.lang.String |
toString62Unit(long number)
To string 62 unit.
|
static java.lang.String |
toString62Unit(short number)
To string 62 unit.
|
static java.lang.String |
toString64Unit(java.math.BigInteger number)
To string 64 unit.
|
static java.lang.String |
toString64Unit(byte number)
To string 64 unit.
|
static java.lang.String |
toString64Unit(int number)
To string 64 unit.
|
static java.lang.String |
toString64Unit(long number)
To string 64 unit.
|
static java.lang.String |
toString64Unit(short number)
To string 64 unit.
|
static <T extends java.lang.Number> |
value(java.lang.Number number,
java.lang.Class<T> toType)
将Number转换为指定数字类型,如果传入数字是null,则返回null
.
|
public static <T extends java.lang.Number> T convert(java.lang.Number number,
java.lang.Class<T> targetClass)
转换数字对象到指定数字类型
.T - 转换后的类型number - 数字targetClass - 转换目标数字类型public static <T extends java.lang.Number> T value(java.lang.Number number,
java.lang.Class<T> toType)
将Number转换为指定数字类型,如果传入数字是null,则返回null
.T - 目标类型泛型number - 数字源toType - 转换目标类型public static <T extends java.lang.Number> T parse(java.lang.String source,
java.lang.Class<T> toType)
将字符串转换为对应的类型,如果传入字符串是null或者空字符串,则返回null
.T - 目标类型泛型source - 转换源字符串toType - 转换目标类型public static java.lang.Byte parse(java.lang.String target,
java.lang.Byte defaultValue)
将传入字符串转换为Byte,如果转换不了则返回传入的默认值
.target - targetdefaultValue - defaultValuepublic static java.lang.Integer parse(java.lang.String target,
java.lang.Integer defaultValue)
将传入字符串转换为Integer,如果转换不了则返回传入的默认值
.target - targetdefaultValue - defaultValuepublic static java.lang.Long parse(java.lang.String target,
java.lang.Long defaultValue)
将传入字符串转换为Long,如果转换不了则返回传入的默认值
.target - targetdefaultValue - defaultValuepublic static java.lang.Double parse(java.lang.String target,
java.lang.Double defaultValue)
将传入字符串转换为Double,如果转换不了则返回传入的默认值
.target - targetdefaultValue - defaultValuepublic static java.lang.Float parse(java.lang.String target,
java.lang.Float defaultValue)
将传入字符串转换为Float,如果转换不了则返回传入的默认值
.target - targetdefaultValue - defaultValuepublic static <N extends java.lang.Number> java.lang.String fillingAtStart(N number,
int minLength,
char sign)
传入数字长度低于传入最小长度则使用传入字符补全在开头使长度达到最小长度
.N - 泛型数字类型number - 数字minLength - 最小长度sign - 补全使用的字符public static byte[] toByteArray(int intSource)
将传入的int转换为长度为4的字节数组
.intSource - intSourcepublic static int toInt(byte[] bytes)
将传入的字节数组转换为int
.bytes - bytespublic static byte[] toByteArray(short shortSource)
将传入的short转换为长度为2的字节数组
.shortSource - shortSourcepublic static short toShort(byte[] bytes)
将传入的字节数组转换为short
.bytes - bytespublic static java.lang.String toString(byte number,
Radix radix)
number - the valueradix - the radixpublic static java.lang.String toString(short number,
Radix radix)
number - the valueradix - the radixpublic static java.lang.String toString(int number,
Radix radix)
number - the valueradix - the radixpublic static java.lang.String toString(long number,
Radix radix)
number - the valueradix - the radixpublic static java.lang.String toString(java.math.BigInteger number,
Radix radix)
number - the valueradix - the radixpublic static java.lang.String toString62Unit(byte number)
number - the numberpublic static java.lang.String toString62Unit(short number)
number - the numberpublic static java.lang.String toString62Unit(int number)
number - the numberpublic static java.lang.String toString62Unit(long number)
number - the numberpublic static java.lang.String toString62Unit(java.math.BigInteger number)
number - the numberpublic static java.lang.String toString64Unit(byte number)
number - the numberpublic static java.lang.String toString64Unit(short number)
number - the numberpublic static java.lang.String toString64Unit(int number)
number - the numberpublic static java.lang.String toString64Unit(long number)
number - the numberpublic static java.lang.String toString64Unit(java.math.BigInteger number)
number - the numberpublic static java.math.BigInteger parse(java.lang.String numberStr,
Radix radix)
numberStr - the number strradix - the radixpublic static int parse62UnitToInt(java.lang.String numberStr)
numberStr - the number strpublic static long parse62UnitToLong(java.lang.String numberStr)
numberStr - the number strpublic static java.math.BigInteger parse62Unit(java.lang.String numberStr)
numberStr - the number strpublic static int parse64UnitToInt(java.lang.String numberStr)
numberStr - the number strpublic static long parse64UnitToLong(java.lang.String numberStr)
numberStr - the number strpublic static java.math.BigInteger parse64Unit(java.lang.String numberStr)
numberStr - the number str