Here you can find the source of objectToInt(Object obj)
public static int objectToInt(Object obj)
//package com.java2s; //License from project: Apache License public class Main { public static int objectToInt(Object obj) { return objectToInt(obj, 0); }// w w w. j a va 2s . co m public static int objectToInt(Object obj, int added) { if (obj instanceof Integer) { return (Integer) obj; } else if (obj instanceof Float) { return ((Float) obj).intValue(); } else if (obj instanceof Double) { return ((Double) obj).intValue(); } return stringToInt(objectToString(obj), added); } public static int stringToInt(String string) { return stringToInt(string, 0); } public static int stringToInt(String string, int added) { int result = 0; try { result = Integer.parseInt(string); } catch (Exception e) { result = added; } return result; } public static String objectToString(Object obj) { return objectToString(obj, null); } public static String objectToString(Object obj, String added) { String result = added; if (obj != null) { result = String.valueOf(obj); } return result; } }