Java Integer Create toInt(String text, int defaultValue)

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

Description

to Int

License

Apache License

Declaration

public static int toInt(String text, int defaultValue) 

Method Source Code

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

public class Main {
    public static int toInt(String text, int defaultValue) {
        if (text == null || text.isEmpty()) {
            return defaultValue;
        }/*w w w.  j a va  2s .  c  o  m*/
        int ret;
        try {
            ret = (int) Double.parseDouble(text);
        } catch (Exception e) {
            return defaultValue;
        }
        return ret;
    }
}

Related

  1. ToInt(String string)
  2. toInt(String string)
  3. toInt(String string)
  4. toInt(String string, int defaultValue)
  5. toInt(String string, int defaultValue)
  6. toInt(String v, int def)
  7. toInt(String value)
  8. toInt(String value)
  9. toInt(String value)