Java Integer Create toInt(String value, int defaultValue)

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

Description

tries to parse the given String into an integer if this fails the default value is returned

License

Apache License

Parameter

Parameter Description
value a parameter
defaultValue a parameter

Declaration

public static int toInt(String value, int defaultValue) 

Method Source Code

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

public class Main {
    /**//from  ww w.  ja v a  2  s .  c  o  m
     * tries to parse the given String into an integer
     * if this fails the default value is returned
     * @param value
     * @param defaultValue
     * @return
     */
    public static int toInt(String value, int defaultValue) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }
}

Related

  1. toInt(String value, int _default)
  2. toInt(String value, int def)
  3. toInt(String value, int defaultValue)
  4. toInt(String value, int defaultValue)
  5. toInt(String value, int defaultValue)
  6. toInt(String value, Integer defaultValue)
  7. toInt(String value, Integer defaultValue)
  8. toInt(String value, Integer fallback)
  9. toInt(String[] a, int off, int len)