Here you can find the source of tryParseInt(Object o)
Object
that may be null or may be an Integer, this method attempts to convert the value to an Integer
.
Parameter | Description |
---|---|
o | the object to try to convert |
Integer
; null otherwise
public static Integer tryParseInt(Object o)
//package com.java2s; //License from project: Apache License public class Main { /**/*from ww w . j a v a2 s .c o m*/ * Given an <code>Object</code> that may be null or may be an Integer, this * method attempts to convert the value to an <code>Integer</code>. If successful, * the <code>Integer</code> value is returned; otherwise, <code>null</code> is returned. * NOTE: the [non-null] object is first converted to a string and is trimmed of whitespace. * @param o the object to try to convert * @return the converted value, if <em>o</em> is an <code>Integer</code>; null otherwise */ public static Integer tryParseInt(Object o) { if (o == null) return null; Integer retVal = null; try { retVal = Integer.parseInt(o.toString().trim()); } catch (NumberFormatException nfe) { } return retVal; } }