Here you can find the source of toInt(String value, int defaultValue)
Parameter | Description |
---|---|
value | string value |
defaultValue | default value |
static public int toInt(String value, int defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww . j a v a2 s . c o m * convert the string to an integer, and return the default value if * the string is null or does not contain a valid int value * * @param value string value * @param defaultValue default value * * @return int */ static public int toInt(String value, int defaultValue) { if (value != null) { try { return Integer.parseInt(value); } catch (NumberFormatException n) { } } return defaultValue; } /** * convert the string to an integer, and return 0 if * the string is null or does not contain a valid int value * * @param value string value * * @return int */ static public int toInt(String value) { if (value != null) { try { return Integer.parseInt(value); } catch (NumberFormatException n) { } } return 0; } }