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