Java Utililty Methods Integer Parse

List of utility methods to do Integer Parse

  1. HOME
  2. Java
  3. I
  4. Integer Parse

Description

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

Method

Integer tryParseInt(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;
...
Integer tryParseInt(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) {
...
int tryParseInt(String intString, int defaultValue)
Try to parse int string, returning -1 if it fails.
try {
 return Integer.parseInt(intString);
} catch (NumberFormatException e) {
 return defaultValue;
Integer tryParseInt(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;
...
int tryParseInt(String s)
try Parse Int
try {
 return Integer.parseInt(s);
} catch (NumberFormatException e) {
 return -1;
Integer tryParseInt(String str)
Tries to parse a String to an Integer
Integer n = null;
try {
 return new Integer(str);
} catch (NumberFormatException nfe) {
 return n;
int tryParseInt(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;
Boolean tryParseInt(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;
Integer tryParseInt(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();
...
Integer tryParseInt(String value)
Try to parse the string as integer or return null if failed
try {
 return Integer.parseInt(value);
} catch (NumberFormatException e) {
 return null;


AltStyle によって変換されたページ (->オリジナル) /