How to convert array of strings to int numbers using parseInt() in Java

1 Answer

0 votes
import java.io.IOException;
 
public class StringsToTntNumbers {
 
    static boolean isNumber(String s) {
        for (int i = 0; i < s.length(); i++) {
            if (!Character.isDigit(s.charAt(i))) {
                return false;
            }
        }
        
        return true;
    }
 
    public static void main(String[] args) throws IOException {
 
        String[] arr = {"F35", "13", "150", "999", "java"};
        for (String s : arr) {
            if (isNumber(s)) {
                int n = Integer.parseInt(s);
                System.out.println(n);
            }
        }
    }
}
 
 

/*
                    
run:
 
13
150
999
           
 */

 



answered Dec 18, 2016 by avibootz
edited May 11 by avibootz
...