Data Types
As the name suggests, data-type specifies the type of the data present in the variable. Variables must be declared with a data-type.
Groovy offers various built-in data types:
Data type | Description | Example |
---|---|---|
int | used to represent whole numbers | int x = 99999 |
short | used to represent whole numbers | short x = 999 |
long | used to represent whole numbers | long x = 99999999999L |
float | used to represent fractional numbers | float x = 22.79f |
double | used to represent fractional numbers | double x = 99.99d |
char | used to represent a single character | char grade = 'A' |
boolean | used to represent Boolean data either true or false | boolean isAvailable = true |
byte | Used to represent a byte value | byte x = 99 |
string | used to represent a series of characters | string msg = "Happy learning!" |
Examples
Check result here
Note:
;
is optional in groovy