I use Groovy as a scripting language, to help me do quick and dirty processing. I often need to reference its syntax. So here’s my personal cheat sheet.
Groovy; Groovy Cheatsheet. Created by Jana Volencova. This section is meant as a quick library of copy/paste code snippets. For details on functions. Here you can find documentation on all of Groovy's commands and features. Add to Discord Commands Premium Support Login 🍪 Hey! Do you like cookies? We do, so we implemented some in our website! Add to Discord Commands Premium Support Login Commands All Basic Player Queue Audio Effects.
Basic
Prints text to the console. For complex GString expressions, use ${expression}.
Loops
Loop a range (both inclusive). Download next driver.
Loop a range (upper exclusive).
Loop a list.
Loop a map.
Closure style looping. The collection being iterated is returned.
Strings
Escaping
Substrings
Tokenizing. Returns ['Hello', 'World!']. Note that using split(' ') in this case (where there are 2 spaces between Hello and World!) will result in 3 elements ['Hello', ', 'World!'].
Regex
Files
Iterate each file in a directory. it is a File object.
Match certain files in directory. See regular expression.
Iterate all files in directory recursively.
Read whole text file.
Read text file line by line.
Write text to file.
Collections
Basic operations
Find first item matching closure. Returns 7.
Find all items matching closure. Returns [7, 11].
Operate on each element. Returns [3, 4, 6, 8].
Join elements into String. Returns '2 3 5 7'.
Date/Time
Basic operations Drivers phoenix.
Groovy Cheat Sheets
JSON
SQL
Connect
Select
Insert/Update/Delete
Batch
One-row
Gradle Cheat Sheet
PostgreSQL import
MySQL import
Threading
Run a thread.
Networking
Grab content from URL. Operations are identical to stream manipulation.
Connect via TCP.
Proxy environment
Misc
Object inspection
Shorthand for Math.pow().
Use ?. notation to help get around NPEs.
GUI - SwingBuilder
Below is an copy-style example of what can be done. Refer to the Widgets List for more documentation. Most bean-style attributes can be directly set in the constructor.
Groovy Regular Expressions Cheat Sheet
Jenkins Groovy Script Examples
From here you can see how to create JFrames, BorderLayout, GridLayout, JPanel, JLabel, JComboBox, Borders, ActionListeners, and how to set their attributes.