Groovy Data Types Classification
Groovy Data Types Classification
The data types supported by Groovy include primitive and reference types. Primitive types encompass integers, floating-point numbers, booleans, and characters, while reference types include strings, lists, maps, ranges, and others.
Below are the data types supported by Groovy along with their examples:
- Integer: The integer data type includes
byte,short,int, andlong. Examples:byte b = 127 short s = 32767 int i = 2147483647 long l = 9223372036854775807L - Floating-point: The floating-point data type includes
floatanddouble. Examples:float f = 3.14F double d = 3.141592653589793 - Boolean: The boolean data type has only two possible values, namely
trueandfalse. Example:boolean flag = true - Character: Character data types are enclosed in single quotes. Example:
char c = 'A' - String: String types are enclosed in double quotes or triple double quotes. Examples:
String str1 = "Hello, world!" String str2 = '''Groovy is awesome! It supports multi-line string.''' - List: List types are enclosed in square brackets. Example:
List list = [1, 2, 3, 4, 5] - Map: Map types are enclosed in curly braces. Example:
Map map = [name: 'John', age: 30] - Range: Range types are connected using
... Example:Range range = 1..10