There are many ways of converting a String to an Integer object. Which is the most efficient among the below:
Integer.valueOf()
Integer.parseInt()
org.apache
Another way is this method:
public class stringtoInteger {
private static int stringtoInteger(String x) {
String value = "";
for (int i = 0; i < x.length(); i++) {
char character = x.charAt(i);
if (Character.isDigit(character)) {
value = value + character;
}
}
return Integer.parseInt(value);
}
}
Hope it helps!