Here you can find the source of castToInt(Object value)
public static final Integer castToInt(Object value)
//package com.java2s; //License from project: Apache License public class Main { public static final Integer castToInt(Object value) { if (value == null) { return null; }// ww w .j a v a 2s .c o m if (value instanceof Integer) { return (Integer) value; } if (value instanceof Number) { return ((Number) value).intValue(); } if (value instanceof String) { String strVal = (String) value; if (strVal.length() == 0) { return null; } if ("null".equals(strVal) || "NULL".equals(strVal)) { return null; } if (strVal.trim().length() == 0) { return null; } return Integer.parseInt(strVal); } throw new NumberFormatException("can not cast to int, value : " + value); } }