CARDINALITY
Description
The CARDINALITY
function is used to calculate the number of elements in an array and the number of key-value pairs in a map.
Syntax
Parameter Description
array
: The input array, with elements of typeT
.map
: The input map, consisting of key typeK
and value typeV
.
Return Type
- Returns an integer (
int
), representing the number of elements in the array or the number of key-value pairs in the map.
Usage Example
- Calculate the number of elements in the array:
- Calculate the number of key-value pairs in the mapping:
- Operate with actual data tables:
Suppose there is a data table named
students
, with the following structure:
Insert a piece of data into the students
table:
Using the CARDINALITY
function to calculate the number of hobbies of the student: