Grails Cookbook - A collection of tutorials and examples

Groovy FindAll

Groovy is popular for writing short and concise codes. Programs that contains many lines of code using Java can be shortened in Groovy. This greatly helps in developer productivity. A feature that is commonly used in Groovy is in searching for items in a collection. The Groovy FindAll method searches for a subset of a collection that matches a given criteria. Here are some examples on how to use Groovy FindAll:

Groovy Find

Groovy is one of the coolest language available because it makes coding so much easier. Long Java codes can be written in Groovy in fewer lines that are much more readable. One of the most used feature in Groovy is in searching. The Groovy Find method can be used to search for a single object in a collection, given a condition on what needs to be searched for. Below are some examples on how to use Groovy Find for searching.

Groovy Def Declaration Examples

When we declare a variable or function in Groovy, we can use the def keyword to define the type. The Groovy Def can be used if we don't want to restrict the type of an object. Hence, we can change what can be assigned to a variable any time during runtime. When we use Groovy def to declare something, it is similar to declaring it as an Object class. Because the class Object is the root class of all classes, you can assign anything to a variable of type Object. Here are some examples on how to use def in Groovy.

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.

Grails Redirect vs Forward

Both redirect and forward methods in controller code will send you to another controller action. This will show the difference between Grails Redirect and Forward.

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.