Oplop98
Oplop98

Reputation: 230

Remove brackets from array in groovy

I have an array that looks like this:

myArray = [[],[],[],[],['test', 'hello'], [], [], [['one', 'two'], ['three','four']], [], ['five']]

I need to remove all these empty objects and more unnecessary brack so my array look like:

['test','hello','one','two','three','four','five']

I tried the following:

myArray.removeAll(['[]'] as Object[]) 

My array then return 'false'. Any ideas how I could remove all the uncessary bracket?

Upvotes: 0

Views: 728

Answers (1)

tim_yates
tim_yates

Reputation: 171084

You can use myArray.flatten() to get your expected result

Upvotes: 3

Related Questions