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 (as determined by whether java.lang.Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned. An exception of type NumberFormatException is thrown if any of the following situations occurs: The first argument is null or is a string of length zero. The radix is either smaller than java.lang.Character.MIN_RADIX or larger than java.lang.Character.MAX_RADIX. Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') provided that the string is longer than length 1. The value represented by the string is not a value of type int. Examples: parseInt("0", 10) returns 0 parseInt("473", 10) returns 473 parseInt("-0", 10) returns 0 parseInt("-FF", 16) returns -255 parseInt("1100110", 2) returns 102 parseInt("2147483647", 10) returns 2147483647 parseInt("-2147483648", 10) returns -2147483648 parseInt("2147483648", 10) throws a NumberFormatException parseInt("99", 8) throws a NumberFormatException parseInt("Kona", 10) throws a NumberFormatException parseInt("Kona", 27) returns 411787
Parameters: s the String containing the integer representation to be parsed radix the radix to be used while parsing s. Returns: the integer represented by the string argument in the specified radix. Throws: NumberFormatException - if the String does not contain a parsable int.
Integer.valueOf用法错用int temp=Integer.valueOf(TestStr).intValue();
你加个2想代表什么?
An exception of type NumberFormatException is thrown if any of the following situations occurs: The first argument is null or is a string of length zero. The radix is either smaller than java.lang.Character.MIN_RADIX or larger than java.lang.Character.MAX_RADIX.
Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') provided that the string is longer than length 1.
The value represented by the string is not a value of type int.
Examples: parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787
Parameters:
s the String containing the integer representation to be parsed
radix the radix to be used while parsing s.
Returns:
the integer represented by the string argument in the specified radix.
Throws:
NumberFormatException - if the String does not contain a parsable int.
其实吧 我是想把它转成二进制的1000,然后转为一个String类型 就变成字符串"1000"
int testInt=Integer.parseInt(TestStr, 2);
结果为testInt = 8 ;
我回答一句 我是做C#的,第三天写JAVA代码,请多见谅!
String testInt=Integer.toBinaryString(i);
System.out.println(testInt);
转成二进制的1000,然后转为一个String类型 就变成字符串"1000"
好吧,这应该是你想要的
我是想把
String TestStr="8"; 转成二进制的 1000
然后在转为String 类型 再赋值给别的变量~
String TestStr="8";
int testInt=Integer.parseInt(TestStr);
String testInt=Integer.toBinaryString(testInt);
System.out.println(testInt);
String str = i.toBinaryString(i) ;
System.out.println(str) ; //1001