Java Integer Create toInt(String value, int def)

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

Description

Convert String to int

License

Apache License

Parameter

Parameter Description
value a parameter
def default value

Declaration

public static int toInt(String value, int def) 

Method Source Code

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

public class Main {
    /**/*from  w w  w . j  av a2 s .c  o m*/
     * Convert String to int
     * @param value
     * @param def default value
     * @return
     */
    public static int toInt(String value, int def) {
        if (isEmpty(value)) {
            return def;
        }
        try {
            return Integer.valueOf(value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return def;
        }
    }

    public static boolean isEmpty(String value) {
        return value == null || "".equals(value);
    }
}

Related

  1. toInt(String value)
  2. toInt(String value)
  3. toInt(String value)
  4. toInt(String value)
  5. toInt(String value, int _default)
  6. toInt(String value, int defaultValue)
  7. toInt(String value, int defaultValue)
  8. toInt(String value, int defaultValue)
  9. toInt(String value, int defaultValue)