Java Integer Parse tryParseInt(String str, int defaultValue)

Here you can find the source of tryParseInt(String str, int defaultValue)

Description

Tries to parse an int from a string, returning the default value on failure

License

Open Source License

Declaration

public static int tryParseInt(String str, int defaultValue) 

Method Source Code

//package com.java2s;
/**/*from  w  ww .j  a v  a  2  s .c  o m*/
 * Copyright (c) 2012 Todoroo Inc
 *
 * See the file "LICENSE" for the full license governing this code.
 */

public class Main {
    /**
     * Tries to parse an int from a string, returning the default value on failure
     */
    public static int tryParseInt(String str, int defaultValue) {
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
}

Related

  1. tryParseInt(Object obj, Integer defaultVal)
  2. tryParseInt(String intString, int defaultValue)
  3. tryParseInt(String num)
  4. tryParseInt(String s)
  5. tryParseInt(String str)
  6. tryParseInt(String stringInt)
  7. tryParseInt(String text)
  8. tryParseInt(String value)
  9. tryParseInt(String value)