Java Integer Create toInt(Object obj)

Here you can find the source of toInt(Object obj)

Description

This method convert object to int.

License

BSD License

Parameter

Parameter Description
obj Object to be convert.

Return

int value.

Declaration

public static int toInt(Object obj) 

Method Source Code

//package com.java2s;
/*L//from   w  ww .j a v  a2  s.c  o m
 * Copyright Washington University in St. Louis, SemanticBits, Persistent Systems, Krishagni.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/commons-module/LICENSE.txt for details.
 */

public class Main {
    /**
     * This method convert object to int.
     * @param obj Object to be convert.
     * @return int value.
     */
    public static int toInt(Object obj) {
        int value = 0;
        if (obj != null) {
            String objVal = String.valueOf(obj);
            if (objVal.length() > 0) {
                Integer intObj = Integer.parseInt(objVal);
                value = intObj.intValue();
            }
        }
        return value;
    }
}

Related

  1. toInt(Object num)
  2. toInt(Object num, int defValue)
  3. toInt(Object o)
  4. toInt(Object o, int defaultValue)
  5. toInt(Object obj)
  6. toInt(Object obj)
  7. toInt(Object obj)
  8. toInt(Object obj)
  9. toInt(Object obj)