Here you can find the source of asInt(String value)
Parameter | Description |
---|---|
value | The String value. |
public static Integer asInt(String value)
//package com.java2s; //License from project: Apache License public class Main { /**/*from ww w . j a va 2 s .co m*/ * Returns the integer corresponding to the given string {@code value}. * * @param value * The {@link String} value. * @return the integer corresponding to the given string {@code value} or {@code null} if the {@code value} does not * contain a parsable integer. */ public static Integer asInt(String value) { return asInt(value, null); } /** * Returns the integer corresponding to the given string {@code value}. * * @param value * The {@link String} value. * @param defaultValue * The default value returned by the method if the given {@code value} is not a valid integer. * @return the integer corresponding to the given string {@code value} or {@code defaultValue} if the {@code value} * does not contain a parsable integer. */ public static Integer asInt(String value, Integer defaultValue) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { return defaultValue; } } }