Here you can find the source of toInt(Object obj)
public static int toInt(Object obj)
//package com.java2s; //License from project: Open Source License public class Main { public static int toInt(Object obj) { return toInt(obj, 0); }/* w w w.java 2s . c o m*/ public static int toInt(Object obj, int defaultValue) { if (obj == null) { return defaultValue; } if (obj instanceof Number) { Number number = (Number) obj; return number.intValue(); } String value = toString(obj); try { return Integer.parseInt(value); } catch (Exception e) { } return defaultValue; } public static String toString(Object value) { if (value == null) { return ""; } return value.toString().trim(); } }