Grails Cookbook - A collection of tutorials and examples

Groovy File Examples

File processing is one of the most common task in programming. Fortunately, Groovy makes file manipulation easier. Things that are long and complicated in Java are now very much concise in Groovy. Here are some Groovy File programming examples.

Grails Render Examples

When coding controllers, we can use the render method to return contents to the browser. Listed below are examples on different ways of using Grails render inside controllers.

Grails Redirect Examples

Grails redirect is a very useful controller method when writing web applications. To redirect flow from one action to the next. Here are some examples on how to use Grails redirect.

Groovy Array Manipulation Examples

When programming in Groovy, we will usually work with lists rather than arrays. In case there is need to work specifically with arrays, below are examples on how to perform different things to a Groovy Array.

Groovy Times Loop Examples

The Groovy times is one of the simplest and most useful method for looping in Groovy. This is very helpful if you know exactly how many times you want to loop and the syntax is as simple as it get. Here are some examples.

Groovy println Examples

The Groovy println method is similar to Java's System.out.println method. This is usually used to display a single line to the screen or console. Here are some Examples.

Groovy print Examples

The Groovy print method is similar to Java's System.out.print method. This method prints a value to the current out variable which can either be the PrintWriter or the standard out. When coding a script, this usually used to display something on the screen. Here are some Examples.

Groovy For Loop Examples

Almost all programs needs some sort of loop construct to execute a block of code several number of times. The "For Loop" is the most common and efficient way to write a loop when you know how many times a task is to be repeated. This will show examples on how to do "For Loop in Groovy". Note that most are also valid Java for loop as Groovy is a superset of Java.

Groovy Sleep Examples

A very common thing we encounter when programming scripts is introducing delays or sleep between statements. In Groovy, sleep method can be used to perform simple delays. Below are some examples.

Groovy List To String

Often times we need to concatenate items of a list to form a String. For example, a comma separated String. There is a nice trick in Groovy on how to convert a Groovy List to String.