Java Integer Create toInt(String number)

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

Description

ToInt converts a string to a integer in a save way

License

Open Source License

Parameter

Parameter Description
number is a String that will be converted to an integer. Number can be null or empty and can contain leading and trailing white space

Return

The integer value represented in the string based on parseInt

Declaration

public static int toInt(String number) 

Method Source Code

//package com.java2s;
/*//from   w w w .j  a va 2 s .c  om
 * LinkIt Tool Chain, an eclipse plugin for LinkIt SDK 1.0 and 2.0
 * 
 * Copyright ? 2015 Henrik Olsson (henols@gmail.com)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * ToInt converts a string to a integer in a save way
     * 
     * @param number
     *            is a String that will be converted to an integer. Number can
     *            be null or empty and can contain leading and trailing white
     *            space
     * @return The integer value represented in the string based on parseInt
     * @see parseInt. After error checking and modifications parseInt is used
     *      for the conversion
     **/
    public static int toInt(String number) {
        if (number == null)
            return 0;
        if (number.equals(""))
            return 0;
        return Integer.parseInt(number.trim());
    }
}

Related

  1. toInt(String arr, String separator)
  2. toInt(String chars)
  3. toInt(String input, int defaultValue)
  4. toInt(String input, int offset, int length)
  5. toInt(String intValue, int defaultValue)
  6. toInt(String numStr, int defaultValue)
  7. toInt(String param)
  8. toInt(String param)
  9. toInt(String pString)