Java Integer Create toInteger(String value, int defaultValue)

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

Description

Parse a string to an integer value, using a given default on fail

License

Open Source License

Parameter

Parameter Description
value a String to parse to an int
defaultValue the default, used when 'value' is not an integer

Return

the parsed value

Declaration

public static int toInteger(String value, int defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w w w . j a  v  a  2 s  .c o  m
     * Parse a string to an integer value, using a given default on fail
     *
     * @param value        a String to parse to an int
     * @param defaultValue the default, used when 'value' is not an integer
     * @return the parsed value
     */
    public static int toInteger(String value, int defaultValue) {
        int ret = defaultValue;
        try {
            ret = Integer.parseInt(value);
        } catch (NumberFormatException e) {
        }
        return ret;
    }
}

Related

  1. toInteger(String value)
  2. toInteger(String value)
  3. toInteger(String value)
  4. toInteger(String value, int _default)
  5. toInteger(String value, int defaultValue)
  6. toInteger(String value, Integer defValue)
  7. toInteger(String[] s)
  8. toInteger(String[] source)
  9. toInteger(StringBuilder value)