Groovy – Logical Operators

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
Logical operators

Logical operators are used to evaluating Boolean expressions. Following are the logical operators available in Groovy −

OperatorDescriptionExample
&&This is the logical “and” operatortrue && true will give true
||This is the logical “or” operatortrue || true will give true
!This is the logical “not” operator!false will give true

The following code snippet shows how the various operators can be used.

class Example { 
   static void main(String[] args) { 
      boolean x = true; 
      boolean y = false; 
      boolean z = true; 
		
      println(x&&y); 
      println(x&&z); 
		
      println(x||z); 
      println(x||y); 
      println(!x); 
   } 
}

When we run the above program, we will get the following result. It can be seen that the results are as expected from the description of the operators as shown above.

false 
true 
true 
true 
false

Next Topic:-Click Here

Leave a Reply