Java Integer Create toInteger(String value)

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

Description

Converts the specified value string to the Integer value.

License

BSD License

Parameter

Parameter Description
value a value string

Exception

Parameter Description
IllegalArgumentException if format error has occured

Return

a Integer object

Declaration

static Integer toInteger(String value) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**//  www .  ja  v  a2 s  . co  m
     * Converts the specified value string to the Integer value.
     * If the specified string is null or blank, this method returns null.
     * 
     * @param value a value string
     * @return a {@code Integer} object
     * @throws IllegalArgumentException if format error has occured
     */
    static Integer toInteger(String value) throws IllegalArgumentException {
        if (value == null || value.equals("")) {
            //the option not specified or a blank value specified
            return null;
        }

        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("invalid boolean value : " + value);
        }
    }
}

Related

  1. toInteger(String str)
  2. toInteger(String string)
  3. toInteger(String string, Integer deff)
  4. toInteger(String val)
  5. toInteger(String value)
  6. toInteger(String value)
  7. toInteger(String value)
  8. toInteger(String value, int _default)
  9. toInteger(String value, int defaultValue)