Grails Cookbook - A collection of tutorials and examples

Groovy String Tokenize Examples

The String class in Groovy has the tokenize() method as a convenient way to tokenize a String or character sequence and return the result as List of String. The given String or character sequence is delimited by whitespace as a default, or can be used passing delimiter as a paramater. Below are some examples on how to use Groovy String's tokenize() method.

Groovy Enum Examples

Enum was introduced in Java to represent a fixed set of constants. Since Groovy is a superset of Java, Enums are also supported in the Groovy programming language. Groovy also adds some enhancements to make working with Enums easier. Below are some examples on how to work with Enums in Groovy.

Groovy Range Examples

Groovy supports a quick way of declaring a list of sequential values using Ranges. In Groovy, a Range can be defined using the .. or ..< notation to declare a list of sequential values. Below are some examples.

Groovy Split Examples

Groovy String has a split() method as a convenience method to split a String or character sequence and return the result as Array of String. The given String or character sequence is split by whitespace as a default, or the given delimiter. Below are some examples on how to use Groovy String's split() method.

Groovy Set Examples

A Set is a collection of objects where all elements are unique and with no duplicates. The elements are not ordered and there are no repeating values. This is a very important data structure on certain programming scenarios. Below are some examples on how we declare and manipulate Sets in Groovy.

Groovy Compare String

We explore different examples of how String comparison behaves in Groovy. Below are some observations on Groovy compare String operations.

Groovy Sort Information in XML Document

Given an XML, we can modify it's contents by sorting the entries based on some criteria. Below is a simple code example on how to do that.

Groovy Edit/Modify XML Examples

Sometimes, it is not enough to parse or create XML documents. There are times when we need to edit an XML information for further processing. Below are examples on how to modify or edit existing XML document.

Groovy Create XML Document Examples

In previous examples, we show how to parse XML documents using XmlSlurper and XmlParser. This post will show the opposite. We give examples on how to create XML documents.

Groovy XmlParser Examples for Parsing XML

Parsing XML information is common to many projects. We showed int he previous post on how to parse XML documents using XmlSlurper. This post will focus on giving examples on how to parse documents using XmlParser.