Here you can find the source of toInt(String str)
public static final int toInt(String str)
//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 <= 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 <= 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(); } }