Here you can find the source of toInteger(String value, int defaultValue)
Parameter | Description |
---|---|
value | a String to parse to an int |
defaultValue | the default, used when 'value' is not an integer |
public static int toInteger(String value, int defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w . j a v a 2 s .c o m * Parse a string to an integer value, using a given default on fail * * @param value a String to parse to an int * @param defaultValue the default, used when 'value' is not an integer * @return the parsed value */ public static int toInteger(String value, int defaultValue) { int ret = defaultValue; try { ret = Integer.parseInt(value); } catch (NumberFormatException e) { } return ret; } }