> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import LightWeightMap from '@ohos.util.LightWeightMap'
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Obtains entries within a range in this container, including the entry at the start position but not that at the end position, and returns these entries as a new **Vector** instance.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fromIndex | number | Yes| Index of the start position.|
| toIndex | number | Yes| Index of the end position.|
**Return value**
| Type| Description|
| -------- | -------- |
| Vector<T> | New **Vector** instance obtained.|
**Return value**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.subVector(2,4);
let result1 = vector.subVector(4,3);
let result2 = vector.subVector(2,6);
```
### clear
clear(): void
Clears all entries in this container and sets its length to **0**.
**Return value**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.clear();
```
### clone
clone(): Vector<T>
Clones this container and returns a copy. The modification to the copy does not affect the original instance.
**Return value**
| Type| Description|
| -------- | -------- |
| Vector<T> | New **Vector** instance obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.clone();
```
### getCapacity
getCapacity(): number
Obtains the capacity of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| number | Capacity obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.getCapacity();
```
### convertToArray
convertToArray(): Array<T>
Converts this container into an array.
**Return value**
| Type| Description|
| -------- | -------- |
| Array<T> | Array obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.convertToArray();
```
### isEmpty
isEmpty(): boolean
Checks whether this container is empty (contains no entries).
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.isEmpty();
```
### increaseCapacityTo
increaseCapacityTo(newCapacity: number): void
Increases the capacity of this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.increaseCapacityTo(2);
vector.increaseCapacityTo(8);
```
### trimToCurrentLength
trimToCurrentLength(): void
Trims the capacity of this container into its current length.
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.trimToCurrentLength();
```
### toString
toString(): string
Uses commas (,) to concatenate entries in this container into a string.
**Return value**
| Type| Description|
| -------- | -------- |
| string | String obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.toSting();
```
### copyToArray
copyToArray(array: Array<T>): void
Copies entries in this container into an array to overwrite elements of the same position indexes.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| array | Array<T> | Yes| Array to which the entries in the container will be copied.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let array = ["a", "b", "c", "d", "e", "f"];
let result = vector.copyToArray(array);
```
### getFirstElement
getFirstElement(): T
Obtains the first entry in this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | The first entry obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.getFirstElement();
```
### getLastElement
getLastElement(): T
Obtains the last entry in this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | The last entry obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.getLastElement();
```
### getLastIndexFrom
getLastIndexFrom(element: T, index: number): number
Searches for an entry backward from the specified position index and returns the position index of the entry.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to query.|
| index | number | Yes| Position index where the search starts.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the entry is not found.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.add("a");
let result = vector.getLastIndexFrom(4,3);
```
### getIndexFrom
getIndexFrom(element: T, index: number): number
Searches for an entry forward from the specified position index and returns the position index of the entry.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to query.|
| index | number | Yes| Position index where the search starts.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the entry is not found.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.add("a");
let result = vector.getIndexFrom(4, 3);
```
### setLength
setLength(newSize: number): void
Sets a new length for this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newSize | number | Yes| New length to set.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.setLength(8);
vector.setLength(2);
```
### get
get(index: number): T
Obtains an entry at the specified position in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the entry to obtain.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry obtained.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.get(2);
```
### set
set(index: number, element: T): T
Replaces an entry at the specified position in this container with a given entry.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the entry to replace.|
| element | T | Yes| Entry to be used for replacement.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | New entry.|
**Example**
```
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.set(2, "A");
```
### [Symbol.iterator]
[Symbol.iterator]\(): IterableIterator<T>
Obtains an iterator. Each item of the iterator is a JavaScript object.