Data Structures
Array Literal, List Literal, Set Literal, Map literal
Was this helpful?
Array Literal, List Literal, Set Literal, Map literal
Was this helpful?
syntax:
An array is a fixed-size, contiguous memory structure that stores elements of the same type.
A
[
followed by zero or more expressions separated by,
and ending with]
, e.g.[ 1, 2, "three" ]
This syntax creates an
Object[]
.Empty array literal can be specified as
[]
with result of creatingObject[]
JEXL will attempt to strongly type the array; if all entries are of the same class or if all entries are Number instance, the array literal will be an
MyClass[]
in the former case, aNumber[]
in the latter case.Furthermore, if all entries in the array literal are of the same class and that class has an equivalent primitive type, the array returned will be a primitive array. e.g.
[1, 2, 3]
will be interpreted asint[]
.
size() -> Integer
: Returns the number of elements in the array.
get(index: Integer) -> T
: Retrieves the element at the specified index
and returns it.
set(index: Integer, value: T)
: Sets the value of the element at the given index
.
A list is a dynamic array-like data structure that can grow or shrink and allows storage of elements of different types.
A
[
followed by zero or more expressions separated by,
and ending with,...]
, e.g.[ 1, 2, "three",...]
This syntax creates an
ArrayList<Object>
.Empty list literal can be specified as
[...]
add(value: T)
: Adds a new element with the provided value to the array.
remove(index: Integer)
: Removes the element at the specified index
.
remove(value: T)
: Removes the first occurrence of the element with the specified value
.
clear()
: Clears all elements from the array.
size(): Integer
Returns the number of elements in the list.
isEmpty():
Boolean Checks if the list is empty and returns true
if it has no elements; otherwise, it returns false
.
static of(): List<T>
Creates and returns an empty list.This class allows you to create and manage lists with elements of a specific data type.
contains(Object o): Boolean
- Returns boolean depending on whether list contains specified parameter.
toArray()
- convert List to Array Data Structure
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.
A
{
followed by zero or more sets ofkey : value
pairs 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
{:}
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.
Or you can define map Manually:
HashMaps are especially useful for defining a row in