Groovy - Lists contains()


Advertisements

Returns true if this List contains the specified value.

Syntax

boolean contains(Object value)

Parameters

Value − The value to find in the list.

Return Value

True or false depending on if the value is present in the list.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      def lst = [11, 12, 13, 14]; 
		
      println(lst.contains(12)); 
      println(lst.contains(18));
   }
}

When we run the above program, we will get the following result −

true 
false
groovy_lists.htm
Advertisements