Convert string to integer
static int parseInt(String s)
- Parses the string argument as a signed decimal integer.
static int parseInt(String s, int radix)
- Parses the string argument in the radix specified by the second argument.
static Integer valueOf(int i)
- Returns a Integer instance representing the specified int value.
static Integer valueOf(String s)
- Returns an Integer object holding the value of the specified String.
static Integer valueOf(String s, int radix)
- Returns an Integer from String based on the radix.
public class Main {
public static void main(String[] args) {
System.out.println(Integer.parseInt("010"));
}
}
The output:
10
You can also indicate the radix.
public class Main {
public static void main(String[] args) {
System.out.println(Integer.parseInt("010",8));
}
}
The output:
8
Home
Java Book
Essential Classes
Java Book
Essential Classes
Integer:
- Integer class
- Max, min value of an integer type variable
- Create Integer using its constructors
- Return an integer value as byte, double, float, int, long and short
- Compare two integer values
- Decode a string and return an integer value
- Convert string to integer
- Convert integer to string
- Reverse and rotate the integer in binary format
- Bit oriented operation
- Return system property as integer
- Get the leading and trailing zeros
- Get the sign of an Integer
- Convert integer to binary, hexdecimal and octal format