1.Integer.parseInt()
String aString = "123"
int b = Integer.parseInt(aString)
System.out.println(b + "")
2.转换为字符串数组再运算
package com.lizi.demo;
public class String2Int {
public static void main(String[] args) {
String aString = "123";
int b = Integer.parseInt(aString);
System.out.println(b + "");
String2Int string2Int = new String2Int();
string2Int.StringToInt(aString);
}
public void StringToInt(String string) {
char[] c = string.toCharArray();
Integer[] intLength = new Integer[c.length];
for (int i = 0; i < c.length; i++) {
intLength[i] = c[i] - '0';
}
Double result = 0D;
for (int i = 0; i < intLength.length; i++) {
result += (intLength[i] * Math.pow(10, (intLength.length - 1 - i)));
}
Integer n = result.intValue();
System.out.println(n + "");
}
}