Here you can find the source of toInt(final String str, int defaultValue)
Parameter | Description |
---|---|
str | a parameter |
defaultValue | a parameter |
public static int toInt(final String str, int defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w . ja va 2 s . c om * Method to convert string to Integer * * @param str * @return {@link int} */ public static int toInt(final String str) { return toInt(str, 0); } /** * Method to convert string to Integer when a default value is given * * @param str * @param defaultValue * @return {@link int} */ public static int toInt(final String str, int defaultValue) { if (str == null) { return defaultValue; } try { return Integer.parseInt(str); } catch (final NumberFormatException exception) { return defaultValue; } } }