Here you can find the source of toInt(Object value, int defaultValue)
public static int toInt(Object value, int defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { public static int toInt(Object value, int defaultValue) { try {/* ww w . j ava 2 s. co m*/ return toInt(value); } catch (Exception e) { return defaultValue; } } public static int toInt(Object value) throws RuntimeException { if (null == value) { throw new RuntimeException("Impossible to convert " + value + " from " + (null == value ? "unknown" : value.getClass() .getName()) + " to " + int.class.getName()); } else if (value instanceof Number) { return ((Number) value).intValue(); } else if (value instanceof String) { try { return Integer.parseInt((String) value); } catch (NumberFormatException e) { throw new RuntimeException("Impossible to convert " + value + " from " + (null == value ? "unknown" : value.getClass() .getName()) + " to " + int.class.getName()); } } throw new RuntimeException("Impossible to convert " + value + " from " + (null == value ? "unknown" : value.getClass().getName()) + " to " + int.class.getName()); } }