Here you can find the source of toInt(String str)
public static int toInt(String str)
//package com.java2s; /**/* w w w .jav a2 s.co m*/ * KTH Developed by Java * * @Copyright 2011 by Service Platform Development Team, KTH, Inc. All rights reserved. * * This software is the confidential and proprietary information of KTH, Inc. * You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with KTH. */ public class Main { public static int toInt(String str) { return toInt(str, 0); } public static int toInt(String str, int defaultValue) { if (str == null) { return defaultValue; } try { return Integer.parseInt(str); } catch (Exception e) { return defaultValue; } } public static int toInt(Object obj) { return toInt(obj, 0); } public static int toInt(Object obj, int defaultValue) { if (obj == null) { return defaultValue; } try { return (Integer) obj; } catch (Exception e) { return defaultValue; } } }