我正在使用以下内容:
int i = Integer.parseInt(args[2]);
还有其他方法可以从字符串中获取整数吗?如果数字确实很小,那么 Byte 和 Char 对象是否提供类似的东西?
最佳答案
是的。有:
Byte.parseByte(s); -- parses a Byte from a String
Short.parseShort(s); -- parses a Short from a String
对于更大的数字,有:
Long.parseLong(s);
-- Float is an imprecise representation of a floating point number using 32 bits
Float.parseFloat(s);
-- Double is an imprecise representation of a floating point number using 64 bits
Double.parseDouble(s);
-- BigIntegers is an integer of arbitrary size as is accurate
new BigInteger(s);
-- BigDecimal is a floating point number of arbitrary size as is accurate
new BigDecimal(s);
关于java - 在Java中如何从字符串中获取整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11274000/