Integer.parseInt(): This method is available in the java.lang.Integer class of Java.
Syntax:
int java.lang.Integer.parseInt(String s) throws NumberFormatException
This method takes one argument of type String as its parameter. This method parses the string argument as a signed decimal integer.
Note: The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-'('\u005Cu002D') to indicate a negative value or an ASCII plus sign '+' ('\u005Cu002B') to indicate a positive value.
Parameters: One parameter is required for this method.
s: a String containing the int representation to be parsed.
Returns: the integer value represented by the argument in decimal.
Throws:
1. NumberFormatException - if the string does not contain a parsable integer.
For Example:
Integer.parseInt("123") = > It returns 123.
Approach
Java
public class IntegerParseInt {public static void main(String[] args) {String str = "123";System.out.println(Integer.parseInt(str));}}
Output:
123
Some other methods of Integer
Integer.bitCount(): It returns the number of one-bits in the two's complement binary representation of the specified int value.
Integer.BYTES: It returns the number of bytes used to represent an int value in the twos-complement binary form.
Integer.compare(): It compares two int values numerically.
Integer.compareUnsigned(): It compares two int values numerically treating the values as unsigned.
Integer.decode(): It decodes a String into an Integer.
Integer.divideUnsigned(): It returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
Integer.getInteger(String nm): It determines the integer value of the system property with the specified name. The first argument is treated as the name of a system property.
Integer.getInteger(String nm, int val): It determines the integer value of the system property with the specified name.
Integer.getInteger(String nm, Integer val): It returns the integer value of the system property with the specified name.
Integer.hashCode(): It returns a hash code for an int value; compatible with Integer.hashCode().
Integer.highestOneBit(): It returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value.
Integer.lowestOneBit(): It returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.
Integer.max(): It returns the greater of two int values.
Integer.MAX_VALUE: A constant holding the maximum value an int can have, 2^31-1 or (2147483647).
Integer.min(): It returns the smaller of two int values.
Integer.MIN_VALUE: A constant holding the minimum value an int can have, -2^31 (-2147483648)
Integer.toString(int Radix): It returns a string representation of the first argument in the radix specified by the second argument.
Integer.toUnsignedLong(): It converts the argument to a long by an unsigned conversion.
Integer.toUnsignedString(): It returns a string representation of the argument as an unsigned decimal value. The argument is converted to unsigned decimal representation and returned as a string.
Integer.valueOf(int): This method returns an Integer instance representing the specified int value.
Integer.toString(int): This method returns a String object representing the specified integer. The argument is converted to signed decimal representation and returned as a string.
Integer.toOctalString(): It returns a string representation of the integer argument as an unsigned integer in base 8. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.
Integer.toHexString(): It returns a string representation of the integer argument as an unsigned integer in base 16. The value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s.
Integer.toBinaryString(): It returns a string representation of the integer argument as an unsigned integer in base 2. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s.
Integer.sum(): It adds two integers together as per the + operator.
Integer.rotateRight(): It returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.
Integer.valueOf(String s, int radix): It returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.
Integer.valueOf(): It returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer. A result is an Integer object that represents the integer value specified by the string.
Integer.SIZE: The number of bits used to represent an int value in twos-complement binary form.
Integer.signum(): It returns the signum function of the specified int value. (The return value is -1 if the specified value is negative; 0 if the specified value is zero; and 1 if the specified value is positive.)
Integer.rotateLeft(): It returns the value obtained by rotating the two's complement binary representation of the specified int value left by the specified number of bits.
Integer.reverseBytes(): It returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value.
Integer.reverse(): It returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified int value.
Integer.remainderUnsigned(): It returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
Integer.parseUnsignedInt(CharSequence): It parses the CharSequence argument as an unsigned int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.
Integer.parseUnsignedInt(String, radix): It parses the string argument as an unsigned integer in the radix specified by the second argument.
Integer.parseUnsignedInt(): It parses the string argument as an unsigned decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII plus sign '+' ('\u005Cu002B').
Integer.parseInt(CharSequence s, int beginIndex, int endIndex,int radix): It parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.
Integer.parseInt(String, int radix): It parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix.
Integer.parseInt(String): It parses the string argument as a signed decimal integer.
Integer.numberOfTrailingZeros(): It returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.
Integer.numberOfLeadingZeros(): It returns the number of zero bits preceding the highest-order("leftmost") one-bit in the two's complement binary representation of the specified int value.
No comments:
Post a Comment