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'] 

1 Answer

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 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.