Java Integer Create toInt(String str, int defaultValue)

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

Description

Convert the string to int.

License

Apache License

Parameter

Parameter Description
value a parameter
defaultValue a parameter

Declaration

public static final int toInt(String str, int defaultValue) 

Method Source Code

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

public class Main {
    /**// ww w  . j av a  2  s .  com
     * Convert the string to int.
     * @param value
     * @param defaultValue
     * @return
     */
    public static final int toInt(String str, int defaultValue) {
        int value = defaultValue;
        if (str == null || str.length() <= 0) {
            return value;
        }
        try {
            value = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            value = defaultValue;
        }
        return value;
    }
}

Related

  1. toInt(String str)
  2. toInt(String str)
  3. toInt(String str)
  4. toInt(String str)
  5. toInt(String str)
  6. toInt(String str, int defaultValue)
  7. toInt(String str, int defValue)
  8. toInt(String str, int val)
  9. toInt(String string)