Java String to Int convertStringToInt(final String strNumber)

Here you can find the source of convertStringToInt(final String strNumber)

Description

Convert a String to a primitive 'int'

License

Creative Commons License

Parameter

Parameter Description
strNumber - the String to convert

Return

return an 'int' number representing the string, or 0 if the number is not valid

Declaration

public static int convertStringToInt(final String strNumber) 

Method Source Code

//package com.java2s;
/**/*from w w w.ja v a  2 s .c  o m*/
 * Generic utility class.
 * <p/>
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License. To
 * view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative
 * Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *
 * @author $Author: jal55 $
 * @version $Rev: 8005 $
 * @package edu.psu.iam.cpr.core.util
 * @lastrevision $Date: 2013-09-11 08:47:10 -0400 (Wed, 11 Sep 2013) $
 */

public class Main {
    /**
     * Convert a String to a primitive 'int'
     *
     * @param strNumber - the String to convert
     * @return return an 'int' number representing the string, or 0 if the number is not valid
     */
    public static int convertStringToInt(final String strNumber) {
        int numericNumber = 0;
        try {
            numericNumber = Integer.parseInt(strNumber);
        }
        // Null, and Empty Strings yield an 'int' of 0
        catch (NumberFormatException nfe) {
        }

        return numericNumber;

    }
}

Related

  1. asInteger(String string)
  2. asInteger(String v)
  3. asInteger(String value)
  4. asInteger(String value)
  5. convertStringToInt(final String str)
  6. convertStringToInt(String number)
  7. convertStringToInt(String str)
  8. convertStringToInt(String value)
  9. convertStringToInteger(String num)