In a previous post I talked about Groovy numbers. In this post we discuss Lists in Groovy. One thing that strikes me is the use of operators in Groovy. Groovy has reduced verbosity wherever possible with the use of operators. We create a List in Java like this: List list = new ArrayList (); and in Groovy like this: def list = [] Why do you think we do not use generics in Groovy? You can reply on Twitter . Groovy allows us to apply several operators like +, -, *, and << //Lets create an empty list. Notice, we can create a list with the [] //operator def aList = [] //size is also an attribute in Lists (we cannot invoke methods //without the ()) println 'size if aList is: ' + aList.size println 'Lists created with the [] operator are of type: ' + aList.class.getName() //What if I want a linked list? def lList = [] as LinkedList println 'lList is of type: ' + lList.class.getName() //We can also create a LinkedList by specifically instantiating it //li...
Write Awesome User Manuals and Tutorials for Software Products