Groovy using the "inject" method to filter items in a list

def list = [1,2,3] def sum = list.inject(0) { sum, item -> sum + item }

The value of sum will be 6.

Author | Miles Davenport

Career programmer, who designs, assembles, fixes, and supports customers, software and systems.