Kajal Kajal - 2 months ago 50
Groovy Question

Findall with array of string groovy

I have a string

. When I split using
I get the following result,


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