Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering empty arrays from array of arrays in Scala

Tags:

arrays

scala

I have an array of arrays of type String, which looks something like:

[[""],["lorem ipsum", "foo", "bar"], [""], ["foo"]]

What I'd like to do is filter out all of the elements in the array that are themselves an empty array (where in this instance, by "empty array", I mean arrays that contain just an empty string), to leave me just with:

[["lorem ipsum", "foo", "bar"], ["foo"]]

However I'm struggling to find a way to do this (still new to Scala) - any help much appreciated!

Thanks.

like image 936
Jack Franklin Avatar asked Jul 17 '12 13:07

Jack Franklin


1 Answers

Edit (with Rogach's simplification):

array.filterNot(_.forall(_.isEmpty))
like image 177
Stefan Endrullis Avatar answered Sep 22 '22 02:09

Stefan Endrullis