ballerina.collections package
public struct IndexOutOfRangeError
An error which is returned when the user attempts to access an element which is out of the Vector's range.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
message | string | The error message | |
cause | error | The cause for the error |
public struct Vector
Vector is a resizable collection type which provides list operations.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
vec | any[] | ||
vectorSize | int | 0 |
-
< Vector > add ( any element )
Adds the specified element to the end of the vector.
Parameter Name Data Type Description element any The element to be added -
< Vector > clear ( )
Clears all the elements from the vector.
-
< Vector > get ( int index ) ( any )
Retrieves the element at the specified position of the vector.
Parameter Name Data Type Description index int The position of the element to retrieve Return Variable Data Type Description any The element at the specified position. -
< Vector > insert ( any element , int index )
Inserts the given element at the position specified. All the elements (including the one currently in the position specified) to the right of the specified position are shifted to the right.
Parameter Name Data Type Description element any The element to insert index int The position to insert the element to -
< Vector > isEmpty ( ) ( boolean )
Checks whether the specified vector is empty.
Return Variable Data Type Description boolean Returns true if there aren't any elements in the vector -
< Vector > remove ( int index ) ( any )
Removes and returns the element at the position specified. All the elements to the right of the specified position are shifted to the left.
Parameter Name Data Type Description index int The position to remove the element from Return Variable Data Type Description any The element at the specified position. -
< Vector > replace ( any element , int index ) ( any )
Replaces the element at the position specified with the provided element.
Parameter Name Data Type Description element any The replacement element index int The position of the element to be replaced Return Variable Data Type Description any The element which was originally at the specified position -
< Vector > size ( ) ( int )
Returns the size of the vector.
Return Variable Data Type Description int The size of the vector