Here you can find the source of toInt(String value)
Parameter | Description |
---|---|
value | A string representing an integer value. |
Parameter | Description |
---|---|
NumberFormatException | if the given value is null, or if thestring can't be parsed as an integer value. |
public static int toInt(String value) throws NumberFormatException
//package com.java2s; /*//w w w .ja v a2s . c om * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2008 - 2010, Geomatys * * This library 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 2.1 of the License, or (at your option) any later version. * * This library 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. */ public class Main { /** * Extends the {@link Integer#valueOf(String)} method, in removing the leading * and trailing whitespace. * * @param value A string representing an integer value. * @return An integer representation of the given string. * @throws NumberFormatException if the given value is {@code null}, or if the * string can't be parsed as an integer value. */ public static int toInt(String value) throws NumberFormatException { if (value == null) { throw new NumberFormatException("Int value not defined."); } value = value.trim(); return Integer.parseInt(value); } }