Groovy web console

subscribe to the feed Subscribe
to this
site

Iterate over

Published 1 month ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def test(value) {
    println "--- ${value?.class?.simpleName} ---"
    if (value instanceof CharSequence) {
        value = [value]
    }
    value?.each {println it}
}

test(42)
test(null)
test([])
test([1, 2, 3])
test(['Hallo', 'Welt!'])
test('Hallo Welt!')
test("Hallo ${'Welt'}!")