- Groovy Tutorial
- Groovy - Home
- Groovy - Overview
- Groovy - Environment
- Groovy - Basic Syntax
- Groovy - Data Types
- Groovy - Variables
- Groovy - Operators
- Groovy - Loops
- Groovy - Decision Making
- Groovy - Methods
- Groovy - File I/O
- Groovy - Optionals
- Groovy - Numbers
- Groovy - Strings
- Groovy - Ranges
- Groovy - Lists
- Groovy - Maps
- Groovy - Dates & Times
- Groovy - Regular Expressions
- Groovy - Exception Handling
- Groovy - Object Oriented
- Groovy - Generics
- Groovy - Traits
- Groovy - Closures
- Groovy - Annotations
- Groovy - XML
- Groovy - JMX
- Groovy - JSON
- Groovy - DSLS
- Groovy - Database
- Groovy - Builders
- Groovy - Command Line
- Groovy - Unit Testing
- Groovy - Template Engines
- Groovy - Meta Object Programming
- Groovy Useful Resources
- Groovy - Quick Guide
- Groovy - Useful Resources
- Groovy - Discussion
Groovy - Logical Operators
Logical operators are used to evaluate Boolean expressions. Following are the logical operators available in Groovy −
Operator | Description | Example |
---|---|---|
&& | This is the logical “and” operator | true && true will give true |
|| | This is the logical “or” operator | true || 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
groovy_operators.htm
Advertisements