Groovy – contains()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
contains

Checks if a range contains a specific value.

Syntax

boolean contains(Object obj)

Parameters

Obj โˆ’ The value to check in the range list.

Return Value

Returns true if this Range contains the specified element.

Example

Following is an example of the usage of this method โˆ’

class Example { 
   static void main(String[] args) { 
      // Example of an Integer using def 
      def rint = 1..10; 
		
      println(rint.contains(2)); 
      println(rint.contains(11)); 
   } 
}

When we run the above program, we will get the following result โˆ’

true 
false

Previous Page:-Click Here

Leave a Reply