Here you can find the source of stringToIntArray(String arrString, String separator)
public static final int[] stringToIntArray(String arrString, String separator)
//package com.java2s; public class Main { public static final int[] stringToIntArray(String arrString, String separator) {//from ww w.j a v a2 s . c o m try { String s = arrString.replaceAll("\\s", ""); String[] sa = s.split(separator); int[] ia = new int[sa.length]; for (int i = 0; i < sa.length; i++) { if (isDigits(sa[i])) { ia[i] = Integer.parseInt(sa[i]); } else { return null; } } return ia; } catch (NumberFormatException e) { return null; } } public static final boolean isDigits(String s) { if (s == null || s.length() == 0) return false; int begin = (s.charAt(0) == '-') ? 1 : 0; for (int i = begin; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) return false; } return true; } public static final boolean isDigits(Object o) { if (o == null) { return false; } String s = o.toString(); if (s.length() == 0) return false; int i = (s.charAt(0) == '-') ? 1 : 0; for (int j = s.length(); i < j; i++) { if (!Character.isDigit(s.charAt(i))) return false; } return true; } }