Java Integer Format formatInt(String value)

Here you can find the source of formatInt(String value)

Description

Checks if the value can safely be converted to a int primitive.

License

Open Source License

Parameter

Parameter Description
value The value validation is being performed on.

Return

format result

Declaration

public static Integer formatInt(String value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  ww  w. ja va 2s. c  o  m
     * Checks if the value can safely be converted to a int primitive.
     *
     * @param value The value validation is being performed on.
     * @return format result
     */
    public static Integer formatInt(String value) {
        if (isBlankOrNull(value)) {
            return null;
        }

        try {
            return new Integer(value);
        } catch (NumberFormatException e) {
            return null;
        }

    }

    /**
     * &ltp&gtChecks if the field isn't null and length of the field is greater than zero not
     * including whitespace.</p>
     *
     * @param value The value validation is being performed on.
     * @return validation result
     */
    public static boolean isBlankOrNull(String value) {
        return ((value == null) || (value.trim().length() == 0) || "null".equalsIgnoreCase(value));
    }
}

Related

  1. formatInt(int n)
  2. formatInt(int value, int length)
  3. formatInt(int value, int numDigit)
  4. formatInt(int value, int width)
  5. formatInt(String value)
  6. formatInt(String value, int defaultValue)
  7. formatInt2(int n)
  8. formatInt64(long val)
  9. formatIntAsDottedOctet(int value)