Alex Rivera | Logout

check if Integer is Null or numeric in groovy?

Asked 2012-05-07T17:18:00.390
8

I have a service method and have to throw an error if method parameter is null/blank or not numeric.

Caller is sending an Integer value but in called method how to check if it is numeric or null.

ex:

def add(value1,value2){
 //have to check value1 is null/blank
 //check value1 is numeric

}

caller: class.add(10,20)

Any suggestions around would be appreciated.

Edit
Report

1 Answer

3

You could try using Groovy's String.isNumber() method.

For example:

if (value1.isNumber()) ...
if (value2.isNumber()) ...
answered 2012-05-07T17:21:23.573

Your Answer