Android Utililty Methods String to Int Convert

List of utility methods to do String to Int Convert

Description

The list of methods to do String to Int Convert are organized into topic(s).

Method

intparseInt(String str)
Parses an string to integer by removing any non-integer character
str = str.replaceAll("[^0-9]+", "");
try {
    return Integer.parseInt(str);
} catch (Exception e) {
    return 0;
intparseInt(String arg, int defaultValue)
parse Int
if (arg == null) {
    return defaultValue;
try {
    return Integer.parseInt(arg);
} catch (NumberFormatException e) {
    return defaultValue;
int[]stringToIntArray(String arrString, String separator)
string To Int Array
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 {
...
ArrayListgetIntegerArrayList(String strInput)
get Integer Array List
ArrayList<Integer> ret = new ArrayList<Integer>();
String[] shareIDs = strInput.split(",");
if (null != shareIDs && shareIDs.length > 0) {
    for (int i = 0; i < shareIDs.length; i++) {
        try {
            ret.add(Integer.valueOf(shareIDs[i]));
        } catch (Exception e) {
            e.printStackTrace();
...
booleanvalidInt(CharSequence integer)
valid Int
if (!TextUtils.isEmpty(integer)) {
    try {
        Integer.parseInt(integer.toString());
        return true;
    } catch (NumberFormatException ex) {
return false;
...
intparseIntOrZero(CharSequence charSequence)
parse Int Or Zero
if (!TextUtils.isEmpty(charSequence)) {
    try {
        return Integer.parseInt(charSequence.toString());
    } catch (NumberFormatException ignore) {
return 0;
intparseInt(String string, int defValue)
Parse String to integer.
try {
    return Integer.parseInt(string);
} catch (NumberFormatException nfe) {
    return defValue;
intconvertStringToInt(String str)
convert String To Int
return convertStringToInt(str, 0);
intconvertStringToInt(String str, int failValue)
convert String To Int
if (str == null) {
    return failValue;
try {
    return Integer.parseInt(str);
} catch (Exception e) {
    e.printStackTrace();
return failValue;