Using Integer paramValue = params.int('paramName') isn't null safe though. If there is no param with the name "paramName" in the param map you get an exception about can't cast null to int.
–
MichaelDec 5 '13 at 21:15

1

just wanted to add, that since Groovy 1.8 int is indeed int. Groovy will still display the Integer class, because of boxing, but you will for example not be able to assign null to an int, which was possible in 1.0. We considered the change being non-critical, since you already could not use null as argument for a method call parameter of type int. This is all still different from Java, as in Java you cannot convert Integer to Long by a simple assignment or call an int taking method with a Long.
–
blackdragFeb 25 at 12:02

As an addendum to Don's answer, not only does groovy add a .toInteger() method to Strings, it also adds toBigDecimal(), toBigInteger(), toBoolean(), toCharacter(), toDouble(), toFloat(), toList(), and toLong().

In the same vein, groovy also adds is* eqivalents to all of those that return true if the String in question can be parsed into the format in question.

This is the correct answer - check first with isInteger(), then do toInteger()... that is, unless you'd rather add a try/catch block :) but using exceptions for this is a bad idea.
–
ankNov 12 '11 at 7:45

@anktastic I'd argue that my answer is more correct because the question asked for "a groovy equivalent of Java's Integer.parseInt(String)", i.e. an unchecked conversion
–
DónalDec 6 '13 at 0:32