4

I have:

List<Tuple2<String, String>> listOfTuples

I would like to have a list of second elements from each Tuple2

Eg.

[Tuple2('1','foo'), Tuple2('2','bar')]

to

['foo','bar']
pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

5

It's easy. You can use Groovy' spread operator to extract a list of the tuple's second elements.

Consider the following example:

def list = [new Tuple2('1','foo'), new Tuple2('2','bar')]

assert ['foo', 'bar'] == list*.second
Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131