Java Integer Create toInteger(String numericString)

Here you can find the source of toInteger(String numericString)

Description

StringUtils.toInteger("") = 0, StringUtils.toInteger(null) = null, StringUtils.toInteger("367 ") = 367, StringUtils.toInteger("someTextHere") = null

License

Open Source License

Parameter

Parameter Description
numericString a parameter

Return

Integer value

Declaration

public static Integer toInteger(String numericString) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w  w w  .  j a va2  s. c  o m*/
     * StringUtils.toInteger("") = 0, StringUtils.toInteger(null) = null, StringUtils.toInteger("367 ") = 367,
     * StringUtils.toInteger("someTextHere") = null
     *
     * @param numericString
     * @return Integer value
     */
    public static Integer toInteger(String numericString) {

        if (numericString == null)
            return null;
        if (numericString.length() == 0)
            return Integer.valueOf(0);
        try {
            return Integer.parseInt(numericString.trim());
        } catch (Exception e) {
            return null;
        }

    }
}

Related

  1. toInteger(Object value, int defaultValue)
  2. toInteger(Object x)
  3. toInteger(String ascii)
  4. toInteger(String integer)
  5. toInteger(String numeric)
  6. toInteger(String pString)
  7. ToInteger(String s)
  8. toInteger(String s)
  9. toInteger(String s)