Here you can find the source of toInt(String number)
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 |
public static int toInt(String number)
//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()); } }