Java Integer Create toInt(String value, Integer defaultValue)

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

Description

to Int

License

Apache License

Declaration

public static Integer toInt(String value, Integer defaultValue) 

Method Source Code

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

public class Main {

    public static Integer toInt(String value, Integer defaultValue) {
        if (value == null || "".equals(value.trim()))
            return defaultValue;
        if (value.startsWith("N") || value.startsWith("n"))
            return -Integer.parseInt(value.substring(1));
        return Integer.parseInt(value);
    }//from   w  w  w .  ja v a2 s .  co m

    public static String substring(String str, int toCount, String more) throws Exception {
        int reInt = 0;
        String reStr = "";
        if (str == null)
            return "";
        char[] tempChar = str.toCharArray();
        for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
            String s1 = String.valueOf(tempChar[kk]);
            byte[] b = s1.getBytes();
            reInt += b.length;
            reStr += tempChar[kk];
        }
        if (toCount == reInt || (toCount == reInt - 1))
            reStr += more;
        return reStr;
    }
}

Related

  1. toInt(String value, int defaultValue)
  2. toInt(String value, int defaultValue)
  3. toInt(String value, int defaultValue)
  4. toInt(String value, int defaultValue)
  5. toInt(String value, Integer defaultValue)
  6. toInt(String value, Integer fallback)
  7. toInt(String[] a, int off, int len)
  8. toInt(String[] s)
  9. toInt(String[] s, int i)