Android String to Int Convert tryParse(String value, String defaultValue)

Here you can find the source of tryParse(String value, String defaultValue)

Description

try Parse

License

Apache License

Declaration

public static String tryParse(String value, String defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static Integer tryParse(String value, int defaultValue) {
        try {//from w  ww . j  av a  2  s . co  m
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }

    public static String tryParse(String value, String defaultValue) {
        try {
            return String.valueOf(Integer.parseInt(value));
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
}

Related

  1. getInt(String str, int defaultValue)
  2. getIntFromStr(String str)
  3. getIntValue(String str)
  4. getFirstInteger(String value)
  5. tryParse(String value, int defaultValue)
  6. parseInt(String str)
  7. parseInt(String arg, int defaultValue)
  8. stringToIntArray(String arrString, String separator)
  9. getIntegerArrayList(String strInput)