I am using the following:
int i = Integer.parseInt(args[2]);
Are there any other ways to get an integer from a string? If the number is really small as it is then doe the Byte and Char objects provide something similar?
Yes. There's:
Byte.parseByte(s); -- parses a Byte from a String
Short.parseShort(s); -- parses a Short from a String
And for larger numbers there's:
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);
int from a BigInteger use .intValue(): ie i4 = new BigInteger(s).intValue();. The BigInteger class is for performing accurate integer arithmetic on arbitrarily large numbers. It has special methods for such arithmetic.Yes, you can use the Short.parseShort(String) and Byte.parseByte(String) wrapper methods to parse smaller integer values.