Kajal Kajal - 11 months ago 148
Groovy Question

Findall with array of string groovy

I have a string

/sample/data
. When I split using
split
I get the following result,

["","sample","data"]


I want to ignore the empty string(s). So I tried the following code,

"/sample/data".split('/').findAll(it != "")


It gives me an error "
cannot call String[] findAll with argument bool
".

How can I split and get a List without empty string in it?

Rao Rao
Answer Source

You can do as below:

println "/sample/data".split('/').findAll {it}

findAll {it} would fetch all the non empty values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download