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

Stringamount2String(String amount)
amount String
String temp = amount.replace(".", "").replace(",", "");
return String.format("%012d", Long.parseLong(temp));
intString2Int(String str)
String Int
try {
    int value = Integer.valueOf(str);
    return value;
} catch (Exception e) {
    e.printStackTrace();
    return 0;
intstring2Int(String str)
string Int
try {
    int value = Integer.valueOf(str);
    return value;
} catch (Exception e) {
    e.printStackTrace();
    return 0;
booleanisTextInteger(String texto)
is Text Integer
boolean out = false;
if (texto != null) {
    texto = texto.toLowerCase().trim();
    try {
        Integer.parseInt(texto);
        return true;
    } catch (Exception e) {
        return false;
...
intgetInt(String str, int defaultValue)
get Int
if (str == null)
    return defaultValue;
try {
    return Integer.parseInt(str);
} catch (Exception e) {
    return defaultValue;
intgetIntFromStr(String str)
get Int From Str
int i = 0;
try {
    i = Integer.valueOf(str);
} catch (NumberFormatException e) {
return i;
intgetIntValue(String str)
get Int Value
if (str != null && str.length() > 0) {
    try {
        return Integer.parseInt(str);
    } catch (Exception e) {
return 0;
intgetFirstInteger(String value)
get First Integer
StringBuilder sb = new StringBuilder();
char[] charArray = value.toCharArray();
for (int i = 0; i < charArray.length; i++) {
    if (charArray[i] >= '0' && charArray[i] <= '9') {
        sb.append(charArray[i]);
    } else {
        break;
return (sb.length() == 0 ? 0 : Integer.parseInt(sb.toString()));
IntegertryParse(String value, int defaultValue)
try Parse
try {
    return Integer.parseInt(value);
} catch (NumberFormatException e) {
    return defaultValue;
StringtryParse(String value, String defaultValue)
try Parse
try {
    return String.valueOf(Integer.parseInt(value));
} catch (NumberFormatException e) {
    return defaultValue;