Java Integer Create toInt(String value, Integer defaultValue)

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

Description

to Int

License

Open Source License

Declaration

public static Integer toInt(String value, Integer defaultValue) 

Method Source Code

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

public class Main {

    public static Integer toInt(String value, Integer defaultValue) {
        if (isEmpty(value))
            return defaultValue;
        try {// w ww. j  ava 2  s. c  o  m
            return Integer.parseInt(value);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static boolean isEmpty(String str) {
        if (str == null)
            return true;

        if ("".equals(str.trim()))
            return true;

        return false;
    }
}

Related

  1. toInt(String value, int def)
  2. toInt(String value, int defaultValue)
  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 fallback)
  8. toInt(String[] a, int off, int len)
  9. toInt(String[] s)