Here you can find the source of toLong(Object obj)
public static long toLong(Object obj)
//package com.java2s; //License from project: Open Source License public class Main { public static long toLong(Object obj) { return toLong(obj, 0L); }//w ww .j ava 2 s .c o m public static long toLong(Object obj, long defaultValue) { if (obj == null) { return defaultValue; } if (obj instanceof Number) { Number number = (Number) obj; return number.longValue(); } String value = toString(obj); try { return Long.parseLong(value); } catch (Exception e) { } return defaultValue; } public static String toString(Object value) { if (value == null) { return ""; } return value.toString().trim(); } }