Java Integer Create toInt(String string, int defaultValue)

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

Description

to Int

License

MIT License

Declaration

public static int toInt(String string, int defaultValue) 

Method Source Code

//package com.java2s;
/*//w w  w  .j ava 2  s  . co  m
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

public class Main {
    public static int toInt(String string, int defaultValue) {
        if (isEmpty(string)) {
            return defaultValue;
        }

        try {
            return Integer.parseInt(string);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public static boolean isEmpty(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }

        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }
}

Related

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