Arrays & Maps
ArrayUtil & MapUtil
Arrays
An ArrayUtil is a dynamic array-like data structure that can store elements of any type. Conceptually, it behaves like an array but with additional functionalities and flexibility.
Methods
ArrayUtils.empty(<T>) -> Array<T>: Returns new empty array of typeT.add(value: T): Adds a value to the array.set(index: Integer, value: T): Sets the value of the element at the givenindex.remove(index: Integer): Removes the value in the array at index.size() -> Integer: returns the size of the array.clear(): Clears the array removing all it's values.
Usage
var array = ArrayUtils.empty(String);
array.add("N");
array.add("B");
array.add("C");
if (array.get(0) == "N") {
    array.set(0, "A");
}
array.add("D");
array.remove(3);
array.clear();
if (array.size() == 0) {
    return true;
}Maps
A map  represented as HashMap<Object, Object>, is a collection that associates unique keys with corresponding values, facilitating efficient retrieval and modification of data based on key references.
Syntax
A
{followed by zero or more sets ofkey : valuepairs separated by,and ending with}, e.g.{ "one" : 1, "two" : 2, "three" : 3, "more": "many more" }This syntax creates a
HashMap<Object,Object>.Empty map literal can be specified as
{:}
Methods
create(); Map
Creates an empty map and returns it.
add(Map<String, Object> map, String key, Object value): void
adds a key-value pair to map. Returns nothing
size(); Integer
Returns number of key-value pairs in map.
isEmpty: Boolean
Returns true of map is empty, otherwise returns false.
cotainsKey(Object key): Boolean
Returns true if map contains specified key, otherwise returns false.
containsValue(Object value): Boolean
Returns true if map contains specified value, otherwise returns false.
remove(String key): Object
Removes key from Map and returns the remove value object.
keySet(); and values();
Return the keys and values of the map, respectively.
Usage
var map = MapUtil.create();
MapUtil.add(map, "name", "steve");
MapUtil.add(map, "age", 40);
MapUtil.add(map, "birthday", LocalDate.now());
map.values(); // returns 2023-11-22,steve,40
map.keySet(); // returns birthday,name,age
map.remove("age"); // remove, age from map and returns 40
return map; Or you can define map Manually:
var map = {
    "name": "steve",
    "age": 40,
    "birthday": LocalDate.now()
}Was this helpful?