Java Integer Create toInt(String s, int defaultInt)

Here you can find the source of toInt(String s, int defaultInt)

Description

A quick an easy way to convert a String into a number, while catching the NumberFormatException and returning a default number if the String is invalid

License

Open Source License

Declaration

public static int toInt(String s, int defaultInt) 

Method Source Code

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

public class Main {
    /**/*from   www  . j a v  a2 s  .c o  m*/
     * A quick an easy way to convert a String into a number, while catching
     * the NumberFormatException and returning a default number if the String is invalid
     */
    public static int toInt(String s, int defaultInt) {
        try {
            return Integer.parseInt(s);
        } catch (NumberFormatException ex) {
            return defaultInt;
        }
    }
}

Related

  1. toInt(String param)
  2. toInt(String pString)
  3. toInt(String s)
  4. toInt(String s)
  5. toInt(String s)
  6. toInt(String s, int exception)
  7. toInt(String sInt)
  8. toInt(String str)
  9. toInt(String str)