Java Utililty Methods Integer Parse

List of utility methods to do Integer Parse

Description

The list of methods to do Integer Parse are organized into topic(s).

Method

IntegertryParseInt(Object o)
Given an Object that may be null or may be an Integer, this method attempts to convert the value to an Integer.
if (o == null)
    return null;
Integer retVal = null;
try {
    retVal = Integer.parseInt(o.toString().trim());
} catch (NumberFormatException nfe) {
return retVal;
...
IntegertryParseInt(Object obj, Integer defaultVal)
try Parse Int
if (obj == null)
    return defaultVal;
if (obj instanceof Integer)
    return (Integer) obj;
try {
    String val = obj.toString();
    return Integer.parseInt(val);
} catch (Exception e) {
...
inttryParseInt(String intString, int defaultValue)
Try to parse int string, returning -1 if it fails.
try {
    return Integer.parseInt(intString);
} catch (NumberFormatException e) {
    return defaultValue;
IntegertryParseInt(String num)
try Parse Int
if (num.length() > 11 || num.length() == 0) {
    return null;
int i = 0;
boolean negative = false;
if (num.charAt(0) == '-') {
    if (num.length() == 1) {
        return null;
...
inttryParseInt(String s)
try Parse Int
try {
    return Integer.parseInt(s);
} catch (NumberFormatException e) {
    return -1;
IntegertryParseInt(String str)
Tries to parse a String to an Integer
Integer n = null;
try {
    return new Integer(str);
} catch (NumberFormatException nfe) {
    return n;
inttryParseInt(String str, int defaultValue)
Tries to parse an int from a string, returning the default value on failure
try {
    return Integer.parseInt(str);
} catch (NumberFormatException e) {
    return defaultValue;
BooleantryParseInt(String stringInt)
Checks if a string is possible to parse into an integer or not.
try {
    Integer.parseInt(stringInt);
    return true;
} catch (Exception e) {
    return false;
IntegertryParseInt(String text)
Attempt to parse the given string as an Integer, but don't throw an exception if it's not a valid integer.
if (text == null)
    return null;
int n;
try {
    String t = text.trim();
    int sign = 1;
    if (t.matches("^\\+.*")) {
        t = t.substring(1).trim();
...
IntegertryParseInt(String value)
Try to parse the string as integer or return null if failed
try {
    return Integer.parseInt(value);
} catch (NumberFormatException e) {
    return null;