Here you can find the source of toLong(Object value)
public static Long toLong(Object value)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w ww. ja v a2s.c o m*/ * Convert an Object to a Long. */ public static Long toLong(Object value) { if (value == null) return null; if (value instanceof Long) return (Long) value; if (value instanceof String) { if ("".equals((String) value)) return null; return new Long((String) value); } if (value instanceof Number) return new Long(((Number) value).shortValue()); return new Long(value.toString()); } /** * Convert an Object to a short, or 0 if it is null. */ public static short shortValue(Object value) { if (value == null) return 0; return toShort(value).shortValue(); } /** * Convert an Object to a Short. */ public static Short toShort(Object value) { if (value == null) return null; if (value instanceof Short) return (Short) value; if (value instanceof String) { if ("".equals((String) value)) return null; return new Short((String) value); } if (value instanceof Number) return new Short(((Number) value).shortValue()); return new Short(value.toString()); } }