Java Integer Create toInt(String str)

Here you can find the source of toInt(String str)

Description

to Int

License

Open Source License

Declaration

public static final int toInt(String str) 

Method Source Code

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

public class Main {
    public static final int toInt(String str) {
        return isValid(str) ? Integer.parseInt(str) : 0;
    }/*from  w  ww .  jav a  2 s  . co m*/

    public static final boolean isValid(String str) {
        return str != null && str.trim().length() > 0;
    }

    /**
     * Gets a String's length or <code>0</code> if the String is
     * <code>null</code>.
     *
     * @param str
     *            a String or <code>null</code>
     * @return String length or <code>0</code> if the String is
     *         <code>null</code>.
     * @since 2.4
     */
    public static int length(String str) {
        return str == null ? 0 : str.length();
    }

    /**
     * <p>
     * Removes control characters (char &lt;= 32) from both ends of this String,
     * handling <code>null</code> by returning <code>null</code>.
     * </p>
     * <p/>
     * <p>
     * The String is trimmed using {@link String#trim()}. Trim removes start and
     * end characters &lt;= 32. To strip whitespace use {@link #strip(String)}.
     * </p>
     * <p/>
     * <p>
     * To trim your choice of characters, use the {@link #strip(String, String)}
     * methods.
     * </p>
     * <p/>
     *
     * <pre>
     * StringUtils.trim(null)          = null
     * StringUtils.trim("")            = ""
     * StringUtils.trim("     ")       = ""
     * StringUtils.trim("abc")         = "abc"
     * StringUtils.trim("    abc    ") = "abc"
     * </pre>
     *
     * @param str
     *            the String to be trimmed, may be null
     * @return the trimmed string, <code>null</code> if null String input
     */
    public static String trim(String str) {
        return str == null ? null : str.trim();
    }
}

Related

  1. toInt(String s)
  2. toInt(String s, int defaultInt)
  3. toInt(String s, int exception)
  4. toInt(String sInt)
  5. toInt(String str)
  6. toInt(String str)
  7. toInt(String str)
  8. toInt(String str)
  9. toInt(String str)