Java Integer Create toInteger(String s)

Here you can find the source of toInteger(String s)

Description

Translate a string s to an Integer.

License

Open Source License

Parameter

Parameter Description
s is the string to parse as an Integer

Return

the integer translation of string s, or return null if s is not an integer.

Declaration

public static Integer toInteger(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w ww .j a va  2  s .  c  o  m*/
     * Translate a string s to an Integer.
     *
     * @param s is the string to parse as an Integer
     * @return the integer translation of string s, or return null if s is not
     * an integer.
     */
    public static Integer toInteger(String s) {
        Integer i = null;
        try {
            i = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            // leave i = null
        }
        return i;
    }

    public static Integer parseInt(String intStr) {
        try {
            int i = Integer.parseInt(intStr);
            return i;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. toInteger(String numeric)
  2. toInteger(String numericString)
  3. toInteger(String pString)
  4. ToInteger(String s)
  5. toInteger(String s)
  6. toInteger(String s, int defValue)
  7. toInteger(String str)
  8. toInteger(String str)
  9. toInteger(String str)