Here you can find the source of toInt(String value, int def)
Parameter | Description |
---|---|
value | a parameter |
def | default value |
public static int toInt(String value, int def)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . j av a2 s .c o m*/ * Convert String to int * @param value * @param def default value * @return */ public static int toInt(String value, int def) { if (isEmpty(value)) { return def; } try { return Integer.valueOf(value); } catch (NumberFormatException e) { e.printStackTrace(); return def; } } public static boolean isEmpty(String value) { return value == null || "".equals(value); } }