Catalog / Groovy Programming Language Cheatsheet
Groovy Programming Language Cheatsheet
A concise cheat sheet covering essential aspects of the Groovy programming language, including syntax, data types, collections, closures, and common operations. This cheat sheet is designed to provide a quick reference for developers working with Groovy, offering a practical overview of the language's core features and capabilities.
Groovy Basics and Syntax
Basic Syntax
Comments |
|
Statements |
Statements do not necessarily need to end with a semicolon (;) |
Variables |
Declared with |
Strings |
Single quotes ( |
Example |
|
Data Types
Primitive Types |
|
Objects |
|
Collections |
|
Ranges |
|
Operators
Arithmetic |
|
Assignment |
|
Comparison |
|
Logical |
|
Safe Navigation |
|
Collections and Closures
Lists
Declaration |
|
Accessing Elements |
|
Adding Elements |
|
Iterating |
|
Maps
Declaration |
|
Accessing Values |
|
Adding/Updating Values |
|
Iterating |
|
Closures
Definition |
|
Calling |
|
Implicit Parameter |
|
Example |
|
Object-Oriented Programming
Classes
Definition |
|
Creating Instances |
|
Getters and Setters |
Automatically generated for class properties. |
Methods
Definition |
|
Calling |
|
Optional Parentheses |
Parentheses can often be omitted.
|
Traits (Interfaces with Implementation)
Definition |
|
Usage |
|
Working with Files and I/O
File Operations
Creating a File |
|
Writing to a File |
|
Reading from a File |
|
Appending to a File |
|
Working with Streams
Reading from InputStream |
|
Writing to OutputStream |
|
Working with URLs
Reading Content from URL |
|