Groovy is one of the most fun language I ever tried to use. Maybe Ruby is equally fun but I have never tried it. Because I came from the Java line of programming, Groovy is more natural to me because it is the superset of Java and I get the chance to use any third party Java library inside Groovy. How fun is that? In this post we discuss another convenience method from String class. We will show how to use Groovy String drop method.
Java developers will just love using Groovy. it is a natural transition because every library that can be used in Java can be used in Groovy, plus we get to use a wonderful programming language that is very convenient to use. For example, the String class reverse method. It reverses a String with no external library necessary to use, nor we need to code anything special. We explore in this post how to use Groovy String reverse method.
The Groovy language provides many convenience method to do cool stuff, specially on String manipulation. In this post, we will check a special way to have a substring of a string using the Take method. We will explore some samples on how to use Groovy String Take method.
It is more convenient that we use Enums in our domain classes rather than String, when we are really sure that Enum is the best representation of a property. Maintaining Strings and constants is just a pain. But it is common problem on how to create a form that accepts Enum values. Below is an example on how to use Select Tag inGrails to choose from Enum values.
When programming in Grails, sometimes we get a String value that we wish to transform to an Enum. For example, when usually get String value from data passed from form or url parameters. Since Groovy 1.7.6, it is now easy to transform a String into a Enum value. Below are some 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.
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 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 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.
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.