Groovy

Groovy programming language tutorials, examples, and best practices.

12 Groovy Substring Techniques Every Developer Needs

Groovy substring extraction with 12 examples covering substring(), subscript operator, take(), drop(), and negative indices. Tested on Groovy 5.0.6. “Extracting the right piece of a string is like cutting a diamond – precision matters, and the right tool makes all the difference.” Last Updated: July 2026 | Tested on: Groovy 5.0.6, Java 17+ | Difficulty: Beginner to Intermediate | Reading Time: 16 minutes When you’re working with strings in Groovy, one of the most common things you’ll need to do ... Read More

10 Proven Groovy String To Integer Conversion Methods You Need

A config value arrives as “8080”, your code needs a port number, and production is a bad place to discover it had a trailing space. Groovy string to integer conversion looks trivial until real input hits it. This post compares toInteger(), Integer.parseInt(), and the as int coercion across 12 tested examples, including safe patterns for input you don’t control. “Type conversion is boring until it throws a NumberFormatException at 2 AM in production. Then it’s suddenly the most important thing ... Read More

10 Useful Groovy -e Command Line Examples to Run Scripts Instantly

You want to check what a regex matches, or how Groovy formats today’s date, and opening an IDE for that feels ridiculous. The groovy command line -e option runs a snippet straight from your terminal, no file required. This post covers the syntax, 10 tested one-liners, and the -n and -p flags that turn Groovy into a text-processing tool. “Why create a file when you can run it right from the command line?” Last Updated: July 2026 | Tested on: ... Read More