1, converted to an integer.
(1) integer.parseint (strings), the code example is as follows:
Common class test {
Public static void main (strinargs []) {
string s = " 123 ";
int num = integer . parse int(str);
int sum = num+ 100;
System.out.println ("The result is:"+sum); //The output result is: The result is: 223.
}}
(2)Integer.valueOf(String s s), the code example is as follows:
Public class Test2 {
Public static void main (strinargs []) {
String s = "-100";
int num = integer . value of(str);
int sum = num+ 10 1;
System.out.println ("The result is:"+sum); //The output result is: The result is: 1.
} }
2. Convert to floating point number
(1) floating-point number. Parsefloat (strings), the code example is as follows:
Common class test {
Public static void main (strinargs []) {
string s = " 123. 1 1 ";
float num = float . parse float(s);
float sum = num+ 100;
System.out.println ("The result is:"+sum); //The output result is: The result is: 223. 1 1.
}}
(2)Double.parseDouble(String s s), the code example is as follows:
Public class Test2 {
Public static void main (strinargs []) {
string s = " 100.0 1 ";
double num = double . parse double(s);
double sum = num+ 100;
System.out.println ("The result is:"+sum); //The output result is: The result is: 200.05438+0.
}}
The specific code required to convert the string s="00000 123+023 "into 123 in the title is as follows:
Common class test {
Public static void main (strinargs []) {
string s = " 00000 123 ";
int num =? integer . parse int(s);
System.out.println ("Result:"+num); //The output result is: The result is: 123.
}}
Extended data:
1, plastic in Java, conversion from floating point to string:
Common class test {
Public static void main (strinargs []) {
int I = 1 1;
string s = I+" "; //Method 1
string s = string . value of(I); //Method 2
string s = integer . tostring(I); //Method 3
} }
2. Judge whether the string is a number in Java:
public static boolean is numeric(String str){
for(int I = str . length(); -I & gt=0; ){
If (! character . is digit(str . charat(I))){
Returns false
} }
Return true
}
Java official document-class string