Integer.parseInt("0", 10) returns 0 Integer.parseInt("473", 10) returns 473 Integer.parseInt("-0", 10) returns 0 Integer.parseInt("-FF", 16) returns -255 Integer.parseInt("1100110", 2) returns 102 Integer.parseInt("2147483647", 10) returns 2147483647 Integer.parseInt("-2147483648", 10) returns -2147483648 Integer.parseInt("2147483648", 10) throws a NumberFormatException Integer.parseInt("99", 8) throws a NumberFormatException Integer.parseInt(" 473", 10) throws a NumberFormatException Integer.parseInt("473", 999) throws a NumberFormatException Integer.parseInt("Kona", 10) throws a NumberFormatException Integer.parseInt("Kona", 27) returns 411787
Double.parseDouble("0") returns 0.0 Double.parseDouble("-NaN") returns 0.0
See also , and . And the constructors , and .
String x = Integer.toString (i, 17); // convert to base 17
java.lang.Math examples: Examples.java output
in, out, err, exit, arraycopy
static byte [] slice (byte [] a, int offset, int length) { byte [] r = new byte [length]; System.arraycopy (a, offset, r, 0, length); return r; }
final File temp = File.createTempFile("prefix-", ".suffix"); temp.deleteOnExit();
String[] strs = {"dog", "pig", "cat"}; Arrays.sort (strs); int[] ints = {9, 5, 1, 7}; Arrays.sort (ints);
Java programs doing simple IO using the Java IO package .
Process p = Runtime.getRuntime().exec ("ls -l");Note that these have to be executable programs not shell "psuedo" commands.
toString conversion Binary operation + converts one, if any, non string argument (either one) to a string before concatenation. Note that println is overloaded it prints int values, String objects, etc. Other objects are converted by using the toString method inherited by all objects.
Integer.toString(n, 16).toUpperCase()might yield 1D2F. There are also the static methods toBinaryString(), toOctalString(), and toHexString().