Does java have a int.tryparse that doesn't throw an exception for bad data? -


possible duplicate:
java: way encapsulate integer.parseint()
how convert string float , avoid using try/catch in java?

c# has int.tryparse: int32.tryparse method (string, int32%)

the great thing method doesn't throw exception bad data.

in java, integer.parseint("abc") throw exception, , in cases may happen lot performance suffer.

is there way around somehow cases performance issue?

the other way can think of run input against regex, have test see faster.

no. have make own this:

boolean tryparseint(string value) {        try {            integer.parseint(value);            return true;         } catch (numberformatexception e) {            return false;         }   } 

...and can use this:

if (tryparseint(input)) {      integer.parseint(input);  // know it's safe parse } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -