Java Integer Create toInt(String str)

Here you can find the source of toInt(String str)

Description

to Int

License

Open Source License

Declaration

public static int toInt(String str) 

Method Source Code

//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;
        }
    }
}

Related

  1. toInt(String str)
  2. toInt(String str)
  3. toInt(String str)
  4. toInt(String str)
  5. toInt(String str)
  6. toInt(String str)
  7. toInt(String str)
  8. toInt(String str)
  9. toInt(String str, int defaultValue)