i was wondering if there’s contains method for collections/array in EL 2.2
or i will have to make a custom one ?
REQUIREMENT: i have a string array, and i want to find if it contains a specific string.
CASE: i am looping on list of input checkboxes to render them, and i want to check the current checkbox, if it’s value exists in the array of checkboxes.
UPDATE:
-
is such method is available in EL?
-
If such method is not available, then please provide your suggestion for best performance method for a string array contains an element.
For a
Collectionit’s easy, just use theColleciton#contains()method in EL.For an
Object[](array), you’d need a minimum of EL 3.0 and utilize its new Lambda support.If you’re not on EL 3.0 yet, you’d need to create a custom EL function. For a concrete example, see How to create a custom EL function to invoke a static method? E.g.
which is registered as
and to be used as
This is not available in JSTL. There’s a
fn:contains(), but that works onStringvalues only.