Here you can find the source of toIntOrNull(String string)
Parameter | Description |
---|---|
string | a parameter |
public static Integer toIntOrNull(String string)
//package com.java2s; /*/*from w w w . j a va 2 s. com*/ * Copyright (C) 2016 Florian Frankenberger. * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * tries to parse the value as int or in case of an error returns null * * @param string * @return */ public static Integer toIntOrNull(String string) { Integer i = null; try { i = Integer.valueOf(string); } catch (NumberFormatException e) { //ignore } return i; } }