int i = Integer.parseInt("blah123yeah4yeah".replaceAll("\\D", ""));
Notice how this will "combine" the numbers from different parts of the lines together into one number. If you only have one number, this still works. If you want only the first number, you can do something like this:
int i = Integer.parseInt("x-42x100x".replaceAll("^\\D*?(-?\\d+).*$", "$1"));
A regular expression is a bit more complicated, but basically replaces the entire string with the first sequence of digits it contains (with an optional minus sign) before using Integer.parseInt for parsing into an integer.
polygenelubricants
source share