Java Utililty Methods Integer Create

List of utility methods to do Integer Create

Description

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

Method

inttoInt(String value, int def)
Convert String to int
if (isEmpty(value)) {
    return def;
try {
    return Integer.valueOf(value);
} catch (NumberFormatException e) {
    e.printStackTrace();
    return def;
...
inttoInt(String value, int defaultValue)
convert the string to an integer, and return the default value if the string is null or does not contain a valid int value
if (value != null) {
    try {
        return Integer.parseInt(value);
    } catch (NumberFormatException n) {
return defaultValue;
inttoInt(String value, int defaultValue)
to Int
try {
    if (value == null || "".equals(value.trim()))
        return defaultValue;
    value = value.trim();
    if (value.startsWith("N") || value.startsWith("n"))
        return -Integer.parseInt(value.substring(1));
    return Integer.parseInt(value);
} catch (Exception e) {
...
inttoInt(String value, int defaultValue)
tries to parse the given String into an integer if this fails the default value is returned
try {
    return Integer.parseInt(value);
} catch (NumberFormatException ex) {
    return defaultValue;
inttoInt(String value, int defaultValue)
Returns the given integer string as an int value.
value = value.trim();
try {
    return Integer.parseInt(value);
} catch (NumberFormatException e) {
    if (value.matches("\\d{10,}"))
        return Integer.MAX_VALUE;
    else if (value.matches("-\\d{10,}"))
        return Integer.MIN_VALUE;
...
IntegertoInt(String value, Integer defaultValue)
to Int
if (isEmpty(value))
    return defaultValue;
try {
    return Integer.parseInt(value);
} catch (Exception e) {
    return defaultValue;
IntegertoInt(String value, Integer defaultValue)
to Int
if (value == null || "".equals(value.trim()))
    return defaultValue;
if (value.startsWith("N") || value.startsWith("n"))
    return -Integer.parseInt(value.substring(1));
return Integer.parseInt(value);
IntegertoInt(String value, Integer fallback)
to Int
if (value == null || value.isEmpty()) {
    return fallback;
try {
    return Integer.valueOf(value);
} catch (Exception e) {
    return fallback;
int[]toInt(String[] a, int off, int len)
to Int
int[] res = new int[len];
for (int i = 0; i < len; i++)
    res[i] = Integer.valueOf(a[off + i]);
return res;
int[]toInt(String[] s)
to Int
int[] result = new int[s.length];
int i = 0;
for (String string : s) {
    result[i++] = Integer.parseInt(string);
return result;