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 typeDescriptionExample
intused to represent whole numbersint x = 99999
shortused to represent whole numbersshort x = 999
longused to represent whole numberslong x = 99999999999L
floatused to represent fractional numbersfloat x = 22.79f
doubleused to represent fractional numbersdouble x = 99.99d
charused to represent a single characterchar grade = 'A'
booleanused to represent Boolean data either true or falseboolean isAvailable = true
byteUsed to represent a byte valuebyte x = 99
stringused to represent a series of charactersstring msg = "Happy learning!"

Examples


Check result here

Note:

; is optional in groovy