java get number out of string

Solutions on MaxInterview for java get number out of string by the best coders in the world

showing results for - "java get number out of string"
Maria
21 Feb 2018
1for(int i=0; i<yourString.length();i++) {
2  if(Character.isDigit(yourString.charAt(i))) {
3    // Do something with the number
4    // For example convert it to int:
5    int yourNumber = Integer.parseInt(String.valueOf(yourString.charAt(i)));
6  }
7}
Anthony
18 May 2020
1public static BigInteger lastBigInteger(String s) {
2    int i = s.length();
3    while (i > 0 && Character.isDigit(s.charAt(i - 1))) {
4        i--;
5    }
6    return new BigInteger(s.substring(i));
7}