提交 50323d78 编写于 作者: Z zengyawen

update docs

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 9d9a5994
...@@ -3,20 +3,26 @@ ...@@ -3,20 +3,26 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
ArrayList是一种线性数据结构,底层基于数组实现。ArrayList会根据实际需要动态调整容量,每次扩容增加50%。
ArrayList和[Vector](js-apis-vector.md)相似,都是基于数组实现。它们都可以动态调整容量,但Vector每次扩容增加1倍。
ArrayList和[LinkedList](js-apis-linkedlist.md)相比,ArrayList的随机访问效率更高。但由于ArrayList的增删操作会影响数组内其他元素的移动,LinkedList的增加和删除操作效率更高。
**推荐使用场景:** 当需要频繁读取集合中的元素时,推荐使用ArrayList。
## 导入模块 ## 导入模块
```ts ```ts
import ArrayList from '@ohos.util.ArrayList'; import ArrayList from '@ohos.util.ArrayList';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## ArrayList ## ArrayList
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | ArrayList的元素个数。 | | length | number | 是 | 否 | ArrayList的元素个数。 |
...@@ -28,6 +34,8 @@ constructor() ...@@ -28,6 +34,8 @@ constructor()
ArrayList的构造函数。 ArrayList的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -41,6 +49,8 @@ add(element: T): boolean ...@@ -41,6 +49,8 @@ add(element: T): boolean
在ArrayList尾部插入元素。 在ArrayList尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -71,6 +81,8 @@ insert(element: T, index: number): void ...@@ -71,6 +81,8 @@ insert(element: T, index: number): void
在长度范围内任意位置插入指定元素。 在长度范围内任意位置插入指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -93,6 +105,8 @@ has(element: T): boolean ...@@ -93,6 +105,8 @@ has(element: T): boolean
判断此ArrayList中是否含有该指定元素。 判断此ArrayList中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -120,6 +134,8 @@ getIndexOf(element: T): number ...@@ -120,6 +134,8 @@ getIndexOf(element: T): number
返回指定元素第一次出现时的下标值,查找失败返回-1。 返回指定元素第一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -152,6 +168,8 @@ getLastIndexOf(element: T): number ...@@ -152,6 +168,8 @@ getLastIndexOf(element: T): number
返回指定元素最后一次出现时的下标值,查找失败返回-1。 返回指定元素最后一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -184,6 +202,8 @@ removeByIndex(index: number): T ...@@ -184,6 +202,8 @@ removeByIndex(index: number): T
根据元素的下标值查找元素,返回元素后将其删除。 根据元素的下标值查找元素,返回元素后将其删除。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -214,6 +234,8 @@ remove(element: T): boolean ...@@ -214,6 +234,8 @@ remove(element: T): boolean
删除查找到的第一个指定的元素。 删除查找到的第一个指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -243,6 +265,8 @@ removeByRange(fromIndex: number, toIndex: number): void ...@@ -243,6 +265,8 @@ removeByRange(fromIndex: number, toIndex: number): void
从一段范围内删除元素,包括起始值但不包括终止值。 从一段范围内删除元素,包括起始值但不包括终止值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -270,6 +294,8 @@ thisArg?: Object): void ...@@ -270,6 +294,8 @@ thisArg?: Object): void
用户操作ArrayList中的元素,用操作后的元素替换原元素并返回操作后的元素。 用户操作ArrayList中的元素,用操作后的元素替换原元素并返回操作后的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -308,6 +334,8 @@ thisArg?: Object): void ...@@ -308,6 +334,8 @@ thisArg?: Object): void
通过回调函数来遍历ArrayList实例对象上的元素以及元素对应的下标。 通过回调函数来遍历ArrayList实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -342,6 +370,8 @@ sort(comparator?: (firstValue: T, secondValue: T) => number): void ...@@ -342,6 +370,8 @@ sort(comparator?: (firstValue: T, secondValue: T) => number): void
对ArrayList中的元素排序。 对ArrayList中的元素排序。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -374,6 +404,8 @@ subArrayList(fromIndex: number, toIndex: number): ArrayList&lt;T&gt; ...@@ -374,6 +404,8 @@ subArrayList(fromIndex: number, toIndex: number): ArrayList&lt;T&gt;
根据下标截取ArrayList中的一段元素,并返回这一段ArrayList实例,包括起始值但不包括终止值。 根据下标截取ArrayList中的一段元素,并返回这一段ArrayList实例,包括起始值但不包括终止值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -406,6 +438,8 @@ clear(): void ...@@ -406,6 +438,8 @@ clear(): void
清除ArrayList中的所有元素,并把length置为0。 清除ArrayList中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -423,6 +457,8 @@ clone(): ArrayList&lt;T&gt; ...@@ -423,6 +457,8 @@ clone(): ArrayList&lt;T&gt;
克隆一个与ArrayList相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。 克隆一个与ArrayList相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
...@@ -447,6 +483,8 @@ getCapacity(): number ...@@ -447,6 +483,8 @@ getCapacity(): number
获取当前实例的容量大小。 获取当前实例的容量大小。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -470,6 +508,8 @@ convertToArray(): Array&lt;T&gt; ...@@ -470,6 +508,8 @@ convertToArray(): Array&lt;T&gt;
把当前ArrayList实例转换成数组,并返回转换后的数组。 把当前ArrayList实例转换成数组,并返回转换后的数组。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -493,6 +533,8 @@ isEmpty(): boolean ...@@ -493,6 +533,8 @@ isEmpty(): boolean
判断该ArrayList是否为空。 判断该ArrayList是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -516,6 +558,8 @@ increaseCapacityTo(newCapacity: number): void ...@@ -516,6 +558,8 @@ increaseCapacityTo(newCapacity: number): void
如果传入的新容量大于或等于ArrayList中的元素个数,将容量变更为新容量。 如果传入的新容量大于或等于ArrayList中的元素个数,将容量变更为新容量。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -540,6 +584,8 @@ trimToCurrentLength(): void ...@@ -540,6 +584,8 @@ trimToCurrentLength(): void
把容量限制为当前的length大小。 把容量限制为当前的length大小。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -557,6 +603,8 @@ arrayList.trimToCurrentLength(); ...@@ -557,6 +603,8 @@ arrayList.trimToCurrentLength();
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Deque(double ended queue)根据循环队列的数据结构实现,符合先进先出以及先进后出的特点,支持两端的元素插入和移除。Deque会根据实际需要动态调整容量,每次进行两倍扩容。
Deque和[Queue](js-apis-queue.md)相比,Queue的特点是先进先出,只能在头部删除元素,尾部增加元素。
[Vector](js-apis-vector.md)相比,它们都支持在两端增删元素,但Deque不能进行中间插入的操作。对头部元素的插入删除效率高于Vector,而Vector访问元素的效率高于Deque。
**推荐使用场景:** 需要频繁在集合两端进行增删元素的操作时,推荐使用Deque。
## 导入模块 ## 导入模块
...@@ -10,14 +17,12 @@ ...@@ -10,14 +17,12 @@
import Deque from '@ohos.util.Deque'; import Deque from '@ohos.util.Deque';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## Deque ## Deque
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | Deque的元素个数。 | | length | number | 是 | 否 | Deque的元素个数。 |
...@@ -28,6 +33,8 @@ constructor() ...@@ -28,6 +33,8 @@ constructor()
Deque的构造函数。 Deque的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -40,6 +47,8 @@ insertFront(element: T): void ...@@ -40,6 +47,8 @@ insertFront(element: T): void
在deque头部插入元素。 在deque头部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -64,6 +73,8 @@ insertEnd(element: T): void ...@@ -64,6 +73,8 @@ insertEnd(element: T): void
在deque尾部插入元素。 在deque尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -88,6 +99,8 @@ has(element: T): boolean ...@@ -88,6 +99,8 @@ has(element: T): boolean
判断此Deque中是否含有该指定元素。 判断此Deque中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -115,6 +128,8 @@ popFirst(): T ...@@ -115,6 +128,8 @@ popFirst(): T
删除并返回双端队列的首元素。 删除并返回双端队列的首元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -139,6 +154,8 @@ popLast(): T ...@@ -139,6 +154,8 @@ popLast(): T
删除并返回双端队列的尾元素。 删除并返回双端队列的尾元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -164,6 +181,8 @@ thisArg?: Object): void ...@@ -164,6 +181,8 @@ thisArg?: Object): void
通过回调函数来遍历Deque实例对象上的元素以及元素对应的下标。 通过回调函数来遍历Deque实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -198,6 +217,8 @@ getFirst(): T ...@@ -198,6 +217,8 @@ getFirst(): T
获取Deque实例中的头元素。 获取Deque实例中的头元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -221,6 +242,8 @@ getLast(): T ...@@ -221,6 +242,8 @@ getLast(): T
获取Deque实例中的尾元素。 获取Deque实例中的尾元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -242,9 +265,10 @@ let result = deque.getLast(); ...@@ -242,9 +265,10 @@ let result = deque.getLast();
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
HashMap底层使用数组+链表+红黑树的方式实现,查询、插入和删除的效率都很高。HashMap存储内容基于key-value的键值对映射,不能有重复的key,且一个key只能对应一个value。
HashMap和[TreeMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存取数据,访问速度较快。而TreeMap是有序存取,效率较低。
[HashSet](js-apis-hashset.md)基于HashMap实现。HashMap的输入参数由key、value两个值组成。在HashSet中,只对value对象进行处理。
**推荐使用场景:** 需要快速存取、删除以及插入键值对数据时,推荐使用HashMap。
## 导入模块 ## 导入模块
...@@ -10,15 +17,12 @@ ...@@ -10,15 +17,12 @@
import HashMap from '@ohos.util.HashMap'; import HashMap from '@ohos.util.HashMap';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## HashMap ## HashMap
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | HashMap的元素个数。 | | length | number | 是 | 否 | HashMap的元素个数。 |
...@@ -30,6 +34,8 @@ constructor() ...@@ -30,6 +34,8 @@ constructor()
HashMap的构造函数。 HashMap的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -43,6 +49,8 @@ isEmpty(): boolean ...@@ -43,6 +49,8 @@ isEmpty(): boolean
判断该HashMap是否为空。 判断该HashMap是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -63,6 +71,8 @@ hasKey(key: K): boolean ...@@ -63,6 +71,8 @@ hasKey(key: K): boolean
判断此HashMap中是否含有该指定key。 判断此HashMap中是否含有该指定key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -91,6 +101,8 @@ hasValue(value: V): boolean ...@@ -91,6 +101,8 @@ hasValue(value: V): boolean
判断此HashMap中是否含有该指定value。 判断此HashMap中是否含有该指定value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -119,6 +131,8 @@ get(key: K): V ...@@ -119,6 +131,8 @@ get(key: K): V
获取指定key所对应的value。 获取指定key所对应的value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -147,6 +161,8 @@ setAll(map: HashMap<K, V>): void ...@@ -147,6 +161,8 @@ setAll(map: HashMap<K, V>): void
将一个HashMap中的所有元素组添加到另一个hashMap中。 将一个HashMap中的所有元素组添加到另一个hashMap中。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -170,6 +186,8 @@ set(key: K, value: V): Object ...@@ -170,6 +186,8 @@ set(key: K, value: V): Object
向HashMap中添加一组数据。 向HashMap中添加一组数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -197,6 +215,8 @@ remove(key: K): V ...@@ -197,6 +215,8 @@ remove(key: K): V
删除指定key所对应元素。 删除指定key所对应元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -225,6 +245,8 @@ clear(): void ...@@ -225,6 +245,8 @@ clear(): void
清除HashMap中的所有元素,并把length置为0。 清除HashMap中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -241,6 +263,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -241,6 +263,8 @@ keys(): IterableIterator&lt;K&gt;
返回包含此映射中包含的键名的新迭代器对象。 返回包含此映射中包含的键名的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -268,6 +292,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -268,6 +292,8 @@ values(): IterableIterator&lt;V&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -295,6 +321,8 @@ replace(key: K, newValue: V): boolean ...@@ -295,6 +321,8 @@ replace(key: K, newValue: V): boolean
对HashMap中一组数据进行更新(替换)。 对HashMap中一组数据进行更新(替换)。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -323,6 +351,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: HashMap<K, V>) => void, thisArg?: ...@@ -323,6 +351,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: HashMap<K, V>) => void, thisArg?:
通过回调函数来遍历HashMap实例对象上的元素以及元素对应的下标。 通过回调函数来遍历HashMap实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -355,6 +385,8 @@ entries(): IterableIterator&lt;[K, V]&gt; ...@@ -355,6 +385,8 @@ entries(): IterableIterator&lt;[K, V]&gt;
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -383,6 +415,8 @@ while(temp != undefined) { ...@@ -383,6 +415,8 @@ while(temp != undefined) {
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
HashSet基于[HashMap](js-apis-hashmap.md)实现。在HashSet中,只对value对象进行处理。
HashSet和[TreeSet](js-apis-treeset.md)相比,HashSet中的数据无序存放,即存放元素的顺序和取出的顺序不一致,而TreeSet是有序存放。它们集合中的元素都不允许重复,但HashSet允许放入null值,TreeSet不允许。
**推荐使用场景:** 可以利用HashSet不重复的特性,当需要不重复的集合或需要去重某个集合的时候使用。
## 导入模块 ## 导入模块
...@@ -10,15 +15,12 @@ ...@@ -10,15 +15,12 @@
import HashSet from '@ohos.util.HashSet'; import HashSet from '@ohos.util.HashSet';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## HashSet ## HashSet
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | HashSet的元素个数。 | | length | number | 是 | 否 | HashSet的元素个数。 |
...@@ -30,6 +32,8 @@ constructor() ...@@ -30,6 +32,8 @@ constructor()
HashSet的构造函数。 HashSet的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -43,6 +47,8 @@ isEmpty(): boolean ...@@ -43,6 +47,8 @@ isEmpty(): boolean
判断该HashSet是否为空。 判断该HashSet是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -63,6 +69,8 @@ has(value: T): boolean ...@@ -63,6 +69,8 @@ has(value: T): boolean
判断此HashSet中是否含有该指定元素。 判断此HashSet中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -91,6 +99,8 @@ add(value: T): boolean ...@@ -91,6 +99,8 @@ add(value: T): boolean
向HashSet中添加数据。 向HashSet中添加数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -117,6 +127,8 @@ remove(value: T): boolean ...@@ -117,6 +127,8 @@ remove(value: T): boolean
删除指定的元素。 删除指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -145,6 +157,8 @@ clear(): void ...@@ -145,6 +157,8 @@ clear(): void
清除HashSet中的所有元素,并把length置为0。 清除HashSet中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -161,6 +175,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -161,6 +175,8 @@ values(): IterableIterator&lt;T&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -188,6 +204,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: HashSet&lt;T&gt;) => void, thisAr ...@@ -188,6 +204,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: HashSet&lt;T&gt;) => void, thisAr
通过回调函数来遍历实例对象上的元素以及元素对应的下标。 通过回调函数来遍历实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -219,6 +237,8 @@ entries(): IterableIterator<[T, T]> ...@@ -219,6 +237,8 @@ entries(): IterableIterator<[T, T]>
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -245,7 +265,9 @@ while(temp != undefined) { ...@@ -245,7 +265,9 @@ while(temp != undefined) {
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
LightWeightMap可用于存储具有关联关系的key-value键值对集合,存储元素中key值唯一,每个key对应一个value。
LightWeightMap依据泛型定义,采用轻量级结构,集合中key值的查找依赖于hash算法,通过一个数组存储hash值,然后映射到其他数组中的key值及value值。
LightWeightMap和[HashMap](js-apis-hashmap.md)都是用来存储键值对的集合,LightWeightMap占用内存更小。
**推荐使用场景:** 当需要存取key-value键值对时,推荐使用占用内存更小的LightWeightMap。
## 导入模块 ## 导入模块
...@@ -10,15 +17,14 @@ ...@@ -10,15 +17,14 @@
import LightWeightMap from '@ohos.util.LightWeightMap'; import LightWeightMap from '@ohos.util.LightWeightMap';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## LightWeightMap ## LightWeightMap
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | LightWeightMap的元素个数。 | | length | number | 是 | 否 | LightWeightMap的元素个数。 |
...@@ -30,6 +36,8 @@ constructor() ...@@ -30,6 +36,8 @@ constructor()
LightWeightMap的构造函数。 LightWeightMap的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -43,6 +51,8 @@ isEmpty(): boolean ...@@ -43,6 +51,8 @@ isEmpty(): boolean
判断该LightWeightMap是否为空。 判断该LightWeightMap是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -63,6 +73,8 @@ hasAll(map: LightWeightMap<K, V>): boolean ...@@ -63,6 +73,8 @@ hasAll(map: LightWeightMap<K, V>): boolean
判断此LightWeightMap中是否含有该指定map中的所有元素。 判断此LightWeightMap中是否含有该指定map中的所有元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -93,6 +105,8 @@ hasKey(key: K): boolean; ...@@ -93,6 +105,8 @@ hasKey(key: K): boolean;
判断此LightWeightMap中是否含有该指定key。 判断此LightWeightMap中是否含有该指定key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -122,6 +136,8 @@ hasValue(value: V): boolean ...@@ -122,6 +136,8 @@ hasValue(value: V): boolean
判断此LightWeightMap中是否含有该指定value。 判断此LightWeightMap中是否含有该指定value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -150,6 +166,8 @@ increaseCapacityTo(minimumCapacity: number): void ...@@ -150,6 +166,8 @@ increaseCapacityTo(minimumCapacity: number): void
将当前LightWeightMap扩容至可以容纳指定数量元素。 将当前LightWeightMap扩容至可以容纳指定数量元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -170,6 +188,8 @@ get(key: K): V ...@@ -170,6 +188,8 @@ get(key: K): V
获取指定key所对应的value。 获取指定key所对应的value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -198,6 +218,8 @@ getIndexOfKey(key: K): number ...@@ -198,6 +218,8 @@ getIndexOfKey(key: K): number
查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -226,6 +248,8 @@ getIndexOfValue(value: V): number ...@@ -226,6 +248,8 @@ getIndexOfValue(value: V): number
查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -254,6 +278,8 @@ getKeyAt(index: number): K ...@@ -254,6 +278,8 @@ getKeyAt(index: number): K
查找指定下标的元素键值对中key值,否则返回undefined。 查找指定下标的元素键值对中key值,否则返回undefined。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -282,6 +308,8 @@ setAll(map: LightWeightMap<K, V>): void ...@@ -282,6 +308,8 @@ setAll(map: LightWeightMap<K, V>): void
将一个LightWeightMap中的所有元素组添加到另一个lightWeightMap中。 将一个LightWeightMap中的所有元素组添加到另一个lightWeightMap中。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -304,6 +332,8 @@ set(key: K, value: V): Object ...@@ -304,6 +332,8 @@ set(key: K, value: V): Object
向LightWeightMap中添加一组数据。 向LightWeightMap中添加一组数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -331,6 +361,8 @@ remove(key: K): V ...@@ -331,6 +361,8 @@ remove(key: K): V
删除并返回指定key映射的元素。 删除并返回指定key映射的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -359,6 +391,8 @@ removeAt(index: number): boolean ...@@ -359,6 +391,8 @@ removeAt(index: number): boolean
删除指定下标对应的元素。 删除指定下标对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -387,6 +421,8 @@ setValueAt(index: number, newValue: V): boolean ...@@ -387,6 +421,8 @@ setValueAt(index: number, newValue: V): boolean
替换指定下标对应键值对中的元素。 替换指定下标对应键值对中的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -416,6 +452,8 @@ getValueAt(index: number): V ...@@ -416,6 +452,8 @@ getValueAt(index: number): V
获取指定下标对应键值对中的元素。 获取指定下标对应键值对中的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -444,6 +482,8 @@ clear(): void ...@@ -444,6 +482,8 @@ clear(): void
清除LightWeightMap中的所有元素,并把length置为0。 清除LightWeightMap中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -460,6 +500,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -460,6 +500,8 @@ keys(): IterableIterator&lt;K&gt;
返回包含此映射中包含的键的新迭代器对象。 返回包含此映射中包含的键的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -487,6 +529,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -487,6 +529,8 @@ values(): IterableIterator&lt;V&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -514,6 +558,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: LightWeightMap<K, V>) => void, th ...@@ -514,6 +558,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: LightWeightMap<K, V>) => void, th
通过回调函数来遍历实例对象上的元素以及元素对应的下标。 通过回调函数来遍历实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -546,6 +592,8 @@ entries(): IterableIterator<[K, V]> ...@@ -546,6 +592,8 @@ entries(): IterableIterator<[K, V]>
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -573,6 +621,8 @@ toString(): String ...@@ -573,6 +621,8 @@ toString(): String
将此映射中包含的键值对拼接成字符串,并返回字符串类型。 将此映射中包含的键值对拼接成字符串,并返回字符串类型。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -594,6 +644,8 @@ toString(): String ...@@ -594,6 +644,8 @@ toString(): String
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,15 @@ ...@@ -3,6 +3,15 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
LightWeightSet可用于存储一系列值的集合,存储元素中value值唯一。
LightWeightSet依据泛型定义,采用轻量级结构,初始默认容量大小为8,每次扩容大小为原始容量的两倍。
集合中value值的查找依赖于hash算法,通过一个数组存储hash值,然后映射到其他数组中的value值。
LightWeightSet和[HashSet](js-apis-hashset.md)都是用来存储键值的集合,LightWeightSet的占用内存更小。
**推荐使用场景:** 当需要存取某个集合或是对某个集合去重时,推荐使用占用内存更小的LightWeightSet。
## 导入模块 ## 导入模块
...@@ -10,15 +19,14 @@ ...@@ -10,15 +19,14 @@
import LightWeightSet from '@ohos.util.LightWeightSet'; import LightWeightSet from '@ohos.util.LightWeightSet';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## LightWeightSet ## LightWeightSet
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | LightWeightSet的元素个数。 | | length | number | 是 | 否 | LightWeightSet的元素个数。 |
...@@ -30,6 +38,8 @@ constructor() ...@@ -30,6 +38,8 @@ constructor()
LightWeightSet的构造函数。 LightWeightSet的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -43,6 +53,8 @@ isEmpty(): boolean ...@@ -43,6 +53,8 @@ isEmpty(): boolean
判断该容器是否为空。 判断该容器是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -62,6 +74,8 @@ add(obj: T): boolean ...@@ -62,6 +74,8 @@ add(obj: T): boolean
向此容器中添加数据。 向此容器中添加数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -88,6 +102,8 @@ addAll(set: LightWeightSet&lt;T&gt;): boolean ...@@ -88,6 +102,8 @@ addAll(set: LightWeightSet&lt;T&gt;): boolean
将另一个容器中的所有元素组添加到当前容器中。 将另一个容器中的所有元素组添加到当前容器中。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -112,6 +128,8 @@ hasAll(set: LightWeightSet&lt;T&gt;): boolean ...@@ -112,6 +128,8 @@ hasAll(set: LightWeightSet&lt;T&gt;): boolean
判断此容器中是否含有该指定set中的所有元素。 判断此容器中是否含有该指定set中的所有元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -142,6 +160,8 @@ has(key: T): boolean ...@@ -142,6 +160,8 @@ has(key: T): boolean
判断此容器中是否含有该指定key。 判断此容器中是否含有该指定key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -170,6 +190,8 @@ equal(obj: Object): boolean ...@@ -170,6 +190,8 @@ equal(obj: Object): boolean
判断此容器中是否含有该指定obj同类型的对象。 判断此容器中是否含有该指定obj同类型的对象。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -199,6 +221,8 @@ increaseCapacityTo(minimumCapacity: number): void ...@@ -199,6 +221,8 @@ increaseCapacityTo(minimumCapacity: number): void
将当前容器扩容至可以容纳指定数量元素。 将当前容器扩容至可以容纳指定数量元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -219,6 +243,8 @@ getIndexOf(key: T): number ...@@ -219,6 +243,8 @@ getIndexOf(key: T): number
获取指定key所对应的下标。 获取指定key所对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -247,6 +273,8 @@ remove(key: T): T ...@@ -247,6 +273,8 @@ remove(key: T): T
删除并返回指定key对应的元素。 删除并返回指定key对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -275,6 +303,8 @@ removeAt(index: number): boolean ...@@ -275,6 +303,8 @@ removeAt(index: number): boolean
删除指定下标所对应的元素。 删除指定下标所对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -303,6 +333,8 @@ getValueAt(index: number): T ...@@ -303,6 +333,8 @@ getValueAt(index: number): T
获取此容器中指定下标对应的元素。 获取此容器中指定下标对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -331,6 +363,8 @@ clear(): void ...@@ -331,6 +363,8 @@ clear(): void
清除容器中的所有元素,并把length置为0。 清除容器中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -347,6 +381,8 @@ toString(): String ...@@ -347,6 +381,8 @@ toString(): String
获取包含容器中所有键和值的字符串。 获取包含容器中所有键和值的字符串。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -369,6 +405,8 @@ toArray(): Array&lt;T&gt; ...@@ -369,6 +405,8 @@ toArray(): Array&lt;T&gt;
获取包含此容器中所有对象的数组。 获取包含此容器中所有对象的数组。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -391,6 +429,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -391,6 +429,8 @@ values(): IterableIterator&lt;T&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -418,6 +458,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: LightWeightSet&lt;T&gt;) => void, ...@@ -418,6 +458,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: LightWeightSet&lt;T&gt;) => void,
通过回调函数来遍历LightWeightSet实例对象上的元素以及元素对应的下标。 通过回调函数来遍历LightWeightSet实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -450,6 +492,8 @@ entries(): IterableIterator<[T, T]> ...@@ -450,6 +492,8 @@ entries(): IterableIterator<[T, T]>
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -477,6 +521,8 @@ while(index < lightWeightSet.length) { ...@@ -477,6 +521,8 @@ while(index < lightWeightSet.length) {
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
LinkedList底层通过双向链表实现,双向链表的每个节点都包含对前一个元素和后一个元素的引用。当需要查询元素时,可以从头遍历,也可以从尾部遍历,插入、删除效率高,查询效率低。LinkedList允许元素为null。
LinkedList和[List](js-apis-list.md)相比,LinkedList是双向链表,可以快速地在头尾进行增删,而List是单向链表,无法双向操作。
LinkedList和[ArrayList](js-apis-arraylist.md)相比,存取数据的效率不如ArrayList。
**推荐使用场景:** 当需要频繁的插入删除时,推荐使用LinkedList高效操作。
## 导入模块 ## 导入模块
...@@ -10,16 +17,15 @@ ...@@ -10,16 +17,15 @@
import LinkedList from '@ohos.util.LinkedList'; import LinkedList from '@ohos.util.LinkedList';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## LinkedList ## LinkedList
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | LinkedList的元素个数。 | | length | number | 是 | 否 | LinkedList的元素个数。 |
...@@ -31,6 +37,8 @@ constructor() ...@@ -31,6 +37,8 @@ constructor()
LinkedList的构造函数。 LinkedList的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
...@@ -45,6 +53,8 @@ add(element: T): boolean ...@@ -45,6 +53,8 @@ add(element: T): boolean
在LinkedList尾部插入元素。 在LinkedList尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -75,6 +85,8 @@ addFirst(element: T): void ...@@ -75,6 +85,8 @@ addFirst(element: T): void
在LinkedList头部插入元素。 在LinkedList头部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -99,6 +111,8 @@ insert(index: number, element: T): void ...@@ -99,6 +111,8 @@ insert(index: number, element: T): void
在长度范围内任意插入指定元素。 在长度范围内任意插入指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -121,6 +135,8 @@ has(element: T): boolean ...@@ -121,6 +135,8 @@ has(element: T): boolean
判断此LinkedList中是否含有该指定元素。 判断此LinkedList中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -148,6 +164,8 @@ get(index: number): T ...@@ -148,6 +164,8 @@ get(index: number): T
根据下标获取LinkedList中的元素。 根据下标获取LinkedList中的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -180,6 +198,8 @@ getLastIndexOf(element: T): number ...@@ -180,6 +198,8 @@ getLastIndexOf(element: T): number
返回指定元素最后一次出现时的下标值,查找失败返回-1。 返回指定元素最后一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -212,6 +232,8 @@ getIndexOf(element: T): number ...@@ -212,6 +232,8 @@ getIndexOf(element: T): number
返回指定元素第一次出现时的下标值,查找失败返回-1。 返回指定元素第一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -244,6 +266,8 @@ removeByIndex(index: number): T ...@@ -244,6 +266,8 @@ removeByIndex(index: number): T
根据元素的下标值查找元素,返回元素后将其删除。 根据元素的下标值查找元素,返回元素后将其删除。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -274,6 +298,8 @@ removeFirst(): T ...@@ -274,6 +298,8 @@ removeFirst(): T
删除并返回LinkedList的第一个元素。 删除并返回LinkedList的第一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -298,6 +324,8 @@ removeLast(): T ...@@ -298,6 +324,8 @@ removeLast(): T
删除并返回LinkedList的最后一个元素。 删除并返回LinkedList的最后一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -322,6 +350,8 @@ remove(element: T): boolean ...@@ -322,6 +350,8 @@ remove(element: T): boolean
删除查找到的第一个指定的元素。 删除查找到的第一个指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -351,6 +381,8 @@ removeFirstFound(element: T): boolean ...@@ -351,6 +381,8 @@ removeFirstFound(element: T): boolean
删除第一次出现的指定元素。 删除第一次出现的指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -380,6 +412,8 @@ removeLastFound(element: T): boolean ...@@ -380,6 +412,8 @@ removeLastFound(element: T): boolean
删除最后一次出现的指定元素。 删除最后一次出现的指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -409,6 +443,8 @@ clone(): LinkedList&lt;T&gt; ...@@ -409,6 +443,8 @@ clone(): LinkedList&lt;T&gt;
克隆一个与LinkedList相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。 克隆一个与LinkedList相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -433,6 +469,8 @@ thisArg?: Object): void ...@@ -433,6 +469,8 @@ thisArg?: Object): void
通过回调函数来遍历LinkedList实例对象上的元素以及元素对应的下标。 通过回调函数来遍历LinkedList实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -467,6 +505,8 @@ clear(): void ...@@ -467,6 +505,8 @@ clear(): void
清除LinkedList中的所有元素,并把length置为0。 清除LinkedList中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -484,6 +524,8 @@ set(index: number, element: T): T ...@@ -484,6 +524,8 @@ set(index: number, element: T): T
将此LinkedList中指定位置的元素替换为指定元素。 将此LinkedList中指定位置的元素替换为指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -514,6 +556,8 @@ convertToArray(): Array&lt;T&gt; ...@@ -514,6 +556,8 @@ convertToArray(): Array&lt;T&gt;
把当前LinkedList实例转换成数组,并返回转换后的数组。 把当前LinkedList实例转换成数组,并返回转换后的数组。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -536,6 +580,8 @@ getFirst(): T ...@@ -536,6 +580,8 @@ getFirst(): T
获取LinkedList实例中的第一个元素。 获取LinkedList实例中的第一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -559,6 +605,8 @@ getLast(): T ...@@ -559,6 +605,8 @@ getLast(): T
获取LinkedList实例中的最后一个元素。 获取LinkedList实例中的最后一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -580,9 +628,10 @@ linkedList.getLast(); ...@@ -580,9 +628,10 @@ linkedList.getLast();
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
List底层通过单向链表实现,每个节点有一个指向后一个元素的引用。当需要查询元素时,必须从头遍历,插入、删除效率高,查询效率低。List允许元素为null。
List和[LinkedList](js-apis-linkedlist.md)相比,LinkedList是双向链表,可以快速地在头尾进行增删,而List是单向链表,无法双向操作。
**推荐使用场景:** 当需要频繁的插入删除时,推荐使用List高效操作。
## 导入模块 ## 导入模块
...@@ -10,16 +15,13 @@ ...@@ -10,16 +15,13 @@
import List from '@ohos.util.List'; import List from '@ohos.util.List';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## List ## List
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | List的元素个数。 | | length | number | 是 | 否 | List的元素个数。 |
...@@ -31,6 +33,8 @@ constructor() ...@@ -31,6 +33,8 @@ constructor()
List的构造函数。 List的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
...@@ -45,6 +49,8 @@ add(element: T): boolean ...@@ -45,6 +49,8 @@ add(element: T): boolean
在List尾部插入元素。 在List尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -75,6 +81,8 @@ insert(element: T, index: number): void ...@@ -75,6 +81,8 @@ insert(element: T, index: number): void
在长度范围内任意位置插入指定元素。 在长度范围内任意位置插入指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -97,6 +105,8 @@ has(element: T): boolean ...@@ -97,6 +105,8 @@ has(element: T): boolean
判断此List中是否含有该指定元素。 判断此List中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -124,6 +134,8 @@ get(index: number): T ...@@ -124,6 +134,8 @@ get(index: number): T
根据下标获取List中的元素。 根据下标获取List中的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -156,6 +168,8 @@ getLastIndexOf(element: T): number ...@@ -156,6 +168,8 @@ getLastIndexOf(element: T): number
查找指定元素最后一次出现的下标值,查找失败返回-1。 查找指定元素最后一次出现的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -188,6 +202,8 @@ getIndexOf(element: T): number ...@@ -188,6 +202,8 @@ getIndexOf(element: T): number
查找指定元素第一次出现的下标值,查找失败返回-1。 查找指定元素第一次出现的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -221,6 +237,8 @@ equal(obj: Object): boolean ...@@ -221,6 +237,8 @@ equal(obj: Object): boolean
比较指定对象与此List是否相等。 比较指定对象与此List是否相等。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -256,6 +274,8 @@ removeByIndex(index: number): T ...@@ -256,6 +274,8 @@ removeByIndex(index: number): T
根据元素的下标值查找元素,返回元素后将其删除。 根据元素的下标值查找元素,返回元素后将其删除。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -286,6 +306,8 @@ remove(element: T): boolean ...@@ -286,6 +306,8 @@ remove(element: T): boolean
删除查找到的第一个指定的元素。 删除查找到的第一个指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -316,6 +338,8 @@ thisArg?: Object): void ...@@ -316,6 +338,8 @@ thisArg?: Object): void
用户操作List中的元素,用操作后的元素替换原元素并返回操作后的元素。 用户操作List中的元素,用操作后的元素替换原元素并返回操作后的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -354,6 +378,8 @@ thisArg?: Object): void ...@@ -354,6 +378,8 @@ thisArg?: Object): void
通过回调函数来遍历List实例对象上的元素以及元素对应的下标。 通过回调函数来遍历List实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -389,6 +415,8 @@ sort(comparator: (firstValue: T, secondValue: T) => number): void ...@@ -389,6 +415,8 @@ sort(comparator: (firstValue: T, secondValue: T) => number): void
对List中的元素进行一个排序操作。 对List中的元素进行一个排序操作。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -420,6 +448,8 @@ getSubList(fromIndex: number, toIndex: number): List&lt;T&gt; ...@@ -420,6 +448,8 @@ getSubList(fromIndex: number, toIndex: number): List&lt;T&gt;
根据下标截取List中的一段元素,并返回这一段List实例,包括起始值但不包括终止值。 根据下标截取List中的一段元素,并返回这一段List实例,包括起始值但不包括终止值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -452,6 +482,8 @@ clear(): void ...@@ -452,6 +482,8 @@ clear(): void
清除List中的所有元素,并把length置为0。 清除List中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -469,6 +501,8 @@ set(index: number, element: T): T ...@@ -469,6 +501,8 @@ set(index: number, element: T): T
将此 List 中指定位置的元素替换为指定元素。 将此 List 中指定位置的元素替换为指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -500,6 +534,8 @@ convertToArray(): Array&lt;T&gt; ...@@ -500,6 +534,8 @@ convertToArray(): Array&lt;T&gt;
把当前List实例转换成数组,并返回转换后的数组。 把当前List实例转换成数组,并返回转换后的数组。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -523,6 +559,8 @@ isEmpty(): boolean ...@@ -523,6 +559,8 @@ isEmpty(): boolean
判断该List是否为空。 判断该List是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -546,6 +584,8 @@ getFirst(): T ...@@ -546,6 +584,8 @@ getFirst(): T
获取List实例中的第一个元素。 获取List实例中的第一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -569,6 +609,8 @@ getLast(): T ...@@ -569,6 +609,8 @@ getLast(): T
获取List实例中的最后一个元素。 获取List实例中的最后一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -590,9 +632,10 @@ let result = list.getLast(); ...@@ -590,9 +632,10 @@ let result = list.getLast();
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
PlainArray可用于存储具有关联关系的key-value键值对集合,存储元素中key值唯一,key值类型为number类型,每个key对应一个value。
PlainArray依据泛型定义,采用轻量级结构,集合中key值的查找依赖于二分查找算法,然后映射到其他数组中的value值。
PlainArray和[LightWeightMap](js-apis-lightweightmap.md)都是用来存储键值对,且均采用轻量级结构,但PlainArray的key值类型只能为number类型。
**推荐使用场景:** 当需要存储key值为number类型的键值对时,可以使用PlainArray。
## 导入模块 ## 导入模块
...@@ -10,15 +17,14 @@ ...@@ -10,15 +17,14 @@
import PlainArray from '@ohos.util.PlainArray'; import PlainArray from '@ohos.util.PlainArray';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## PlainArray ## PlainArray
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | PlainArray的元素个数。 | | length | number | 是 | 否 | PlainArray的元素个数。 |
...@@ -30,6 +36,8 @@ constructor() ...@@ -30,6 +36,8 @@ constructor()
PlainArray的构造函数。 PlainArray的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -43,6 +51,8 @@ isEmpty(): boolean ...@@ -43,6 +51,8 @@ isEmpty(): boolean
判断该容器是否为空。 判断该容器是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -63,6 +73,8 @@ has(key: number): boolean ...@@ -63,6 +73,8 @@ has(key: number): boolean
判断此容器中是否含有该指定key。 判断此容器中是否含有该指定key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -91,6 +103,8 @@ get(key: number): T ...@@ -91,6 +103,8 @@ get(key: number): T
获取指定key所对应的value。 获取指定key所对应的value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -119,6 +133,8 @@ getIndexOfKey(key: number): number ...@@ -119,6 +133,8 @@ getIndexOfKey(key: number): number
查找指定key第一次出现的下标值,如果没有找到该key返回-1。 查找指定key第一次出现的下标值,如果没有找到该key返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -147,6 +163,8 @@ getIndexOfValue(value: T): number ...@@ -147,6 +163,8 @@ getIndexOfValue(value: T): number
查找指定value元素第一次出现的下标值,如果没有找到该value元素返回-1。 查找指定value元素第一次出现的下标值,如果没有找到该value元素返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -175,6 +193,8 @@ getKeyAt(index: number): number ...@@ -175,6 +193,8 @@ getKeyAt(index: number): number
查找指定下标的元素键值对中key值。 查找指定下标的元素键值对中key值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -202,6 +222,8 @@ getValueAt(index: number): T ...@@ -202,6 +222,8 @@ getValueAt(index: number): T
查找指定下标元素键值对中Value值,否则返回undefined。 查找指定下标元素键值对中Value值,否则返回undefined。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -229,6 +251,8 @@ clone(): PlainArray&lt;T&gt; ...@@ -229,6 +251,8 @@ clone(): PlainArray&lt;T&gt;
克隆一个实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。 克隆一个实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -251,6 +275,8 @@ add(key: number, value: T): void ...@@ -251,6 +275,8 @@ add(key: number, value: T): void
向容器中添加一组数据。 向容器中添加一组数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -272,6 +298,8 @@ remove(key: number): T ...@@ -272,6 +298,8 @@ remove(key: number): T
删除指定key对应元素。 删除指定key对应元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -301,6 +329,8 @@ removeAt(index: number): T ...@@ -301,6 +329,8 @@ removeAt(index: number): T
删除指定下标对应的元素。 删除指定下标对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -330,6 +360,8 @@ removeRangeFrom(index: number, size: number): number ...@@ -330,6 +360,8 @@ removeRangeFrom(index: number, size: number): number
删除一定范围内的元素。 删除一定范围内的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -359,6 +391,8 @@ setValueAt(index: number, value: T): void ...@@ -359,6 +391,8 @@ setValueAt(index: number, value: T): void
替换容器中指定下标对应键值对中的键值。 替换容器中指定下标对应键值对中的键值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -382,6 +416,8 @@ toString(): String ...@@ -382,6 +416,8 @@ toString(): String
获取包含容器中所有键和值的字符串。 获取包含容器中所有键和值的字符串。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -404,6 +440,8 @@ clear(): void ...@@ -404,6 +440,8 @@ clear(): void
清除容器中的所有元素,并把length置为0。 清除容器中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -420,6 +458,8 @@ forEach(callbackfn: (value: T, index?: number, PlainArray?: PlainArray&lt;T&gt;) ...@@ -420,6 +458,8 @@ forEach(callbackfn: (value: T, index?: number, PlainArray?: PlainArray&lt;T&gt;)
通过回调函数来遍历实例对象上的元素以及元素对应的下标。 通过回调函数来遍历实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -452,6 +492,8 @@ plainArray.forEach((value, index) => { ...@@ -452,6 +492,8 @@ plainArray.forEach((value, index) => {
返回一个迭代器,迭代器的每一项都是一个 JavaScript对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Queue的特点是先进先出,在尾部增加元素,在头部删除元素。根据循环队列的数据结构实现。
Queue和[Deque](js-apis-deque.md)相比,Queue只能在一端删除一端增加,Deque可以两端增删。
**推荐使用场景:** 一般符合先进先出的场景可以使用Queue。
## 导入模块 ## 导入模块
...@@ -10,16 +15,13 @@ ...@@ -10,16 +15,13 @@
import Queue from '@ohos.util.Queue'; import Queue from '@ohos.util.Queue';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## Queue ## Queue
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | Queue的元素个数。 | | length | number | 是 | 否 | Queue的元素个数。 |
...@@ -31,6 +33,8 @@ constructor() ...@@ -31,6 +33,8 @@ constructor()
Queue的构造函数。 Queue的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -44,6 +48,8 @@ add(element: T): boolean ...@@ -44,6 +48,8 @@ add(element: T): boolean
在队列尾部插入元素。 在队列尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -75,6 +81,8 @@ pop(): T ...@@ -75,6 +81,8 @@ pop(): T
删除头元素并返回该删除元素。 删除头元素并返回该删除元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -99,6 +107,8 @@ getFirst(): T ...@@ -99,6 +107,8 @@ getFirst(): T
获取队列的头元素。 获取队列的头元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -123,6 +133,8 @@ thisArg?: Object): void ...@@ -123,6 +133,8 @@ thisArg?: Object): void
通过回调函数来遍历Queue实例对象上的元素以及元素对应的下标。 通过回调函数来遍历Queue实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -156,9 +168,10 @@ queue.forEach((value, index) => { ...@@ -156,9 +168,10 @@ queue.forEach((value, index) => {
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Stack基于数组的数据结构实现,特点是先进后出,只能在一端进行数据的插入和删除。
Stack和[Queue](js-apis-queue.md)相比,Queue基于循环队列实现,只能在一端删除,另一端插入,而Stack都在一端操作。
**推荐使用场景:** 一般符合先进后出的场景可以使用Stack。
## 导入模块 ## 导入模块
...@@ -10,16 +15,15 @@ ...@@ -10,16 +15,15 @@
import Stack from '@ohos.util.Stack'; import Stack from '@ohos.util.Stack';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## Stack ## Stack
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | Stack的元素个数。 | | length | number | 是 | 否 | Stack的元素个数。 |
...@@ -31,6 +35,8 @@ constructor() ...@@ -31,6 +35,8 @@ constructor()
Stack的构造函数。 Stack的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -44,6 +50,8 @@ push(item: T): T ...@@ -44,6 +50,8 @@ push(item: T): T
在栈顶插入元素,并返回该元素。 在栈顶插入元素,并返回该元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -74,6 +82,8 @@ pop(): T ...@@ -74,6 +82,8 @@ pop(): T
删除栈顶元素并返回该删除元素。 删除栈顶元素并返回该删除元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -98,6 +108,8 @@ peek(): T ...@@ -98,6 +108,8 @@ peek(): T
获取并返回栈顶元素。 获取并返回栈顶元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -121,6 +133,8 @@ locate(element: T): number ...@@ -121,6 +133,8 @@ locate(element: T): number
返回指定元素第一次出现时的下标值,查找失败返回-1。 返回指定元素第一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -151,6 +165,8 @@ thisArg?: Object): void ...@@ -151,6 +165,8 @@ thisArg?: Object): void
通过回调函数来遍历Stack实例对象上的元素以及元素对应的下标。 通过回调函数来遍历Stack实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -185,6 +201,8 @@ isEmpty(): boolean ...@@ -185,6 +201,8 @@ isEmpty(): boolean
判断该栈是否为空。 判断该栈是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -206,9 +224,10 @@ let result = stack.isEmpty(); ...@@ -206,9 +224,10 @@ let result = stack.isEmpty();
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
TreeMap可用于存储具有关联关系的key-value键值对集合,存储元素中key值唯一,每个key对应一个value。
TreeMap底层使用红黑树实现,可以利用二叉树特性快速查找键值对。key值有序存储,可以实现快速的插入和删除。
TreeMap和[HashMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存取数据,访问速度较快。而TreeMap是有序存取,效率较低。
**推荐使用场景:** 一般需要存储有序键值对的场景,可以使用TreeMap。
## 导入模块 ## 导入模块
...@@ -10,15 +17,12 @@ ...@@ -10,15 +17,12 @@
import TreeMap from '@ohos.util.TreeMap'; import TreeMap from '@ohos.util.TreeMap';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## TreeMap ## TreeMap
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | TreeMap的元素个数。 | | length | number | 是 | 否 | TreeMap的元素个数。 |
...@@ -30,6 +34,8 @@ constructor(comparator?:(firstValue: K, secondValue: K) => boolean) ...@@ -30,6 +34,8 @@ constructor(comparator?:(firstValue: K, secondValue: K) => boolean)
TreeMap的构造函数。 TreeMap的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -49,6 +55,8 @@ isEmpty(): boolean ...@@ -49,6 +55,8 @@ isEmpty(): boolean
判断该容器是否为空。 判断该容器是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -69,6 +77,8 @@ hasKey(key: K): boolean ...@@ -69,6 +77,8 @@ hasKey(key: K): boolean
判断此容器中是否含有该指定key。 判断此容器中是否含有该指定key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -97,6 +107,8 @@ hasValue(value: V): boolean ...@@ -97,6 +107,8 @@ hasValue(value: V): boolean
判断此容器中是否含有该指定value。 判断此容器中是否含有该指定value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -125,6 +137,8 @@ get(key: K): V ...@@ -125,6 +137,8 @@ get(key: K): V
获取指定key所对应的value。 获取指定key所对应的value。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -153,6 +167,8 @@ getFirstKey(): K ...@@ -153,6 +167,8 @@ getFirstKey(): K
获取容器中排序第一的key。 获取容器中排序第一的key。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -175,6 +191,8 @@ getLastKey(): K ...@@ -175,6 +191,8 @@ getLastKey(): K
获取容器中排序最后的key。 获取容器中排序最后的key。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -197,6 +215,8 @@ setAll(map: TreeMap<K, V>): void ...@@ -197,6 +215,8 @@ setAll(map: TreeMap<K, V>): void
将一个TreeMap中的所有元素组添加到另一个TreeMap中。 将一个TreeMap中的所有元素组添加到另一个TreeMap中。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -220,6 +240,8 @@ set(key: K, value: V): Object ...@@ -220,6 +240,8 @@ set(key: K, value: V): Object
向容器中添加一组数据。 向容器中添加一组数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -247,6 +269,8 @@ remove(key: K): V ...@@ -247,6 +269,8 @@ remove(key: K): V
删除指定key对应的元素。 删除指定key对应的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -275,6 +299,8 @@ getLowerKey(key: K): K ...@@ -275,6 +299,8 @@ getLowerKey(key: K): K
获取容器中比传入key排序靠前一位的key。 获取容器中比传入key排序靠前一位的key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -304,6 +330,8 @@ getHigherKey(key: K): K ...@@ -304,6 +330,8 @@ getHigherKey(key: K): K
获取容器中比传入key排序靠后一位的key。 获取容器中比传入key排序靠后一位的key。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -332,6 +360,8 @@ replace(key: K, newValue: V): boolean ...@@ -332,6 +360,8 @@ replace(key: K, newValue: V): boolean
对容器中一组数据进行更新(替换)。 对容器中一组数据进行更新(替换)。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -360,6 +390,8 @@ clear(): void ...@@ -360,6 +390,8 @@ clear(): void
清除容器中的所有元素,并把length置为0。 清除容器中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -376,6 +408,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -376,6 +408,8 @@ keys(): IterableIterator&lt;K&gt;
返回包含此映射中包含的键的新迭代器对象。 返回包含此映射中包含的键的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -403,6 +437,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -403,6 +437,8 @@ values(): IterableIterator&lt;V&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -430,6 +466,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: TreeMap<K, V>) => void, thisArg?: ...@@ -430,6 +466,8 @@ forEach(callbackfn: (value?: V, key?: K, map?: TreeMap<K, V>) => void, thisArg?:
通过回调函数来遍历实例对象上的元素以及元素对应的下标。 通过回调函数来遍历实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -462,6 +500,8 @@ entries(): IterableIterator<[K, V]> ...@@ -462,6 +500,8 @@ entries(): IterableIterator<[K, V]>
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -488,9 +528,10 @@ while(temp != undefined) { ...@@ -488,9 +528,10 @@ while(temp != undefined) {
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt; [Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
TreeSet基于[TreeMap](js-apis-treemap.md)实现,在TreeSet中,只对value对象进行处理。TreeSet可用于存储一系列值的集合,元素中value唯一且有序。
TreeSet和[HashSet](js-apis-hashset.md)相比,HashSet中的数据无序存放,而TreeSet是有序存放。它们集合中的元素都不允许重复,但HashSet允许放入null值,TreeSet不允许。
**推荐使用场景:** 一般需要存储有序集合的场景,可以使用TreeSet。
## 导入模块 ## 导入模块
...@@ -10,15 +15,12 @@ ...@@ -10,15 +15,12 @@
import TreeSet from '@ohos.util.TreeSet'; import TreeSet from '@ohos.util.TreeSet';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## TreeSet ## TreeSet
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | TreeSet的元素个数。 | | length | number | 是 | 否 | TreeSet的元素个数。 |
...@@ -30,6 +32,8 @@ constructor(comparator?:(firstValue: T, secondValue: T) => boolean) ...@@ -30,6 +32,8 @@ constructor(comparator?:(firstValue: T, secondValue: T) => boolean)
TreeSet的构造函数。 TreeSet的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -49,6 +53,8 @@ isEmpty(): boolean ...@@ -49,6 +53,8 @@ isEmpty(): boolean
判断该容器是否为空。 判断该容器是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -69,6 +75,8 @@ has(value: T): boolean ...@@ -69,6 +75,8 @@ has(value: T): boolean
判断此容器中是否含有该指定元素。 判断此容器中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -97,6 +105,8 @@ getFirstValue(): T ...@@ -97,6 +105,8 @@ getFirstValue(): T
获取容器中排序第一的数据。 获取容器中排序第一的数据。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -119,6 +129,8 @@ getLastValue(): T ...@@ -119,6 +129,8 @@ getLastValue(): T
获取容器中排序最后的数据。 获取容器中排序最后的数据。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -141,6 +153,8 @@ add(value: T): boolean ...@@ -141,6 +153,8 @@ add(value: T): boolean
向容器中添加一组数据。 向容器中添加一组数据。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -167,6 +181,8 @@ remove(value: T): boolean ...@@ -167,6 +181,8 @@ remove(value: T): boolean
删除指定的元素。 删除指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -195,6 +211,8 @@ getLowerValue(key: T): T ...@@ -195,6 +211,8 @@ getLowerValue(key: T): T
获取容器中比传入元素排序靠前一位的元素。 获取容器中比传入元素排序靠前一位的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -224,6 +242,8 @@ getHigherValue(key: T): T ...@@ -224,6 +242,8 @@ getHigherValue(key: T): T
获取容器中比传入元素排序靠后一位的元素。 获取容器中比传入元素排序靠后一位的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -253,6 +273,8 @@ popFirst(): T ...@@ -253,6 +273,8 @@ popFirst(): T
删除容器中排序最前的数据。 删除容器中排序最前的数据。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -275,6 +297,8 @@ popLast(): T ...@@ -275,6 +297,8 @@ popLast(): T
删除容器中排序最后的数据。 删除容器中排序最后的数据。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -297,6 +321,8 @@ clear(): void ...@@ -297,6 +321,8 @@ clear(): void
清除容器中的所有元素,并把length置为0。 清除容器中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -313,6 +339,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -313,6 +339,8 @@ values(): IterableIterator&lt;T&gt;
返回包含此映射中包含的键值的新迭代器对象。 返回包含此映射中包含的键值的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -340,6 +368,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: TreeSet&lt;T&gt;) => void, thisAr ...@@ -340,6 +368,8 @@ forEach(callbackfn: (value?: T, key?: T, set?: TreeSet&lt;T&gt;) => void, thisAr
通过回调函数来遍历实例对象上的元素以及元素对应的下标。 通过回调函数来遍历实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -372,6 +402,8 @@ entries(): IterableIterator<[T, T]> ...@@ -372,6 +402,8 @@ entries(): IterableIterator<[T, T]>
返回包含此映射中包含的键值对的新迭代器对象。 返回包含此映射中包含的键值对的新迭代器对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -398,9 +430,10 @@ while(temp != undefined) { ...@@ -398,9 +430,10 @@ while(temp != undefined) {
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Vector是一种线性数据结构,底层基于数组实现。当Vector的内存用尽时,会自动分配更大的连续内存区,将原先的元素复制到新的内存区,并释放旧的内存区。使用Vector能够高效快速地访问元素。
Vector和[ArrayList](js-apis-arraylist.md)相似,都是基于数组实现,但Vector提供了更多操作数组的接口。它们都可以动态调整容量,但Vector每次扩容增加1倍,ArrayList只扩容0.5倍。
**推荐使用场景:** 当数据量大时,一般使用Vector来存取数据。
## 导入模块 ## 导入模块
...@@ -10,16 +15,13 @@ ...@@ -10,16 +15,13 @@
import Vector from '@ohos.util.Vector'; import Vector from '@ohos.util.Vector';
``` ```
## 系统能力
SystemCapability.Utils.Lang
## Vector ## Vector
### 属性 ### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | Vector的元素个数。 | | length | number | 是 | 否 | Vector的元素个数。 |
...@@ -31,6 +33,8 @@ constructor() ...@@ -31,6 +33,8 @@ constructor()
Vector的构造函数。 Vector的构造函数。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -44,6 +48,8 @@ add(element: T): boolean ...@@ -44,6 +48,8 @@ add(element: T): boolean
在Vector中尾部插入元素。 在Vector中尾部插入元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -74,6 +80,8 @@ insert(element: T, index: number): void ...@@ -74,6 +80,8 @@ insert(element: T, index: number): void
在长度范围内任意插入指定元素。 在长度范围内任意插入指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -96,6 +104,8 @@ has(element: T): boolean ...@@ -96,6 +104,8 @@ has(element: T): boolean
判断此Vector中是否含有该指定元素。 判断此Vector中是否含有该指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -123,6 +133,8 @@ getIndexOf(element: T): number ...@@ -123,6 +133,8 @@ getIndexOf(element: T): number
返回指定元素第一次出现时的下标值,查找失败返回-1。 返回指定元素第一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -155,6 +167,8 @@ getLastIndexOf(element: T): number ...@@ -155,6 +167,8 @@ getLastIndexOf(element: T): number
返回指定元素最后一次出现时的下标值,查找失败返回-1。 返回指定元素最后一次出现时的下标值,查找失败返回-1。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -187,6 +201,8 @@ removeByIndex(index: number): T ...@@ -187,6 +201,8 @@ removeByIndex(index: number): T
根据元素的下标值查找元素,返回元素后将其删除。 根据元素的下标值查找元素,返回元素后将其删除。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -217,6 +233,8 @@ remove(element: T): boolean ...@@ -217,6 +233,8 @@ remove(element: T): boolean
删除查找到的第一个指定的元素。 删除查找到的第一个指定的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -246,6 +264,8 @@ removeByRange(fromIndex: number, toIndex: number): void ...@@ -246,6 +264,8 @@ removeByRange(fromIndex: number, toIndex: number): void
从一段范围内删除元素,包括起始值但不包括终止值。 从一段范围内删除元素,包括起始值但不包括终止值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -273,6 +293,8 @@ thisArg?: Object): void ...@@ -273,6 +293,8 @@ thisArg?: Object): void
用户操作Vector中的元素,用操作后的元素替换原元素并返回操作后的元素。 用户操作Vector中的元素,用操作后的元素替换原元素并返回操作后的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -311,6 +333,8 @@ thisArg?: Object): void ...@@ -311,6 +333,8 @@ thisArg?: Object): void
通过回调函数来遍历Vector实例对象上的元素以及元素对应的下标。 通过回调函数来遍历Vector实例对象上的元素以及元素对应的下标。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -346,6 +370,8 @@ sort(comparator?: (firstValue: T, secondValue: T) => number): void ...@@ -346,6 +370,8 @@ sort(comparator?: (firstValue: T, secondValue: T) => number): void
对Vector中的元素进行一个排序操作。 对Vector中的元素进行一个排序操作。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -378,6 +404,8 @@ subVector(fromIndex: number, toIndex: number): Vector&lt;T&gt; ...@@ -378,6 +404,8 @@ subVector(fromIndex: number, toIndex: number): Vector&lt;T&gt;
根据下标截取Vector中的一段元素,并返回这一段vector实例,包括起始值但不包括终止值。 根据下标截取Vector中的一段元素,并返回这一段vector实例,包括起始值但不包括终止值。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -411,6 +439,8 @@ clear(): void ...@@ -411,6 +439,8 @@ clear(): void
清除Vector中的所有元素,并把length置为0。 清除Vector中的所有元素,并把length置为0。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
```ts ```ts
...@@ -428,6 +458,8 @@ clone(): Vector&lt;T&gt; ...@@ -428,6 +458,8 @@ clone(): Vector&lt;T&gt;
克隆一个与Vector相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。 克隆一个与Vector相同的实例,并返回克隆后的实例。修改克隆后的实例并不会影响原实例。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -451,6 +483,8 @@ getCapacity(): number ...@@ -451,6 +483,8 @@ getCapacity(): number
获取当前实例的容量大小。 获取当前实例的容量大小。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -474,6 +508,8 @@ convertToArray(): Array&lt;T&gt; ...@@ -474,6 +508,8 @@ convertToArray(): Array&lt;T&gt;
把当前Vector实例转换成数组,并返回转换后的数组。 把当前Vector实例转换成数组,并返回转换后的数组。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -497,6 +533,8 @@ isEmpty(): boolean ...@@ -497,6 +533,8 @@ isEmpty(): boolean
判断该Vector是否为空。 判断该Vector是否为空。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -520,6 +558,8 @@ increaseCapacityTo(newCapacity: number): void ...@@ -520,6 +558,8 @@ increaseCapacityTo(newCapacity: number): void
如果传入的新容量大于或等于Vector中的元素个数,将容量变更为新容量。 如果传入的新容量大于或等于Vector中的元素个数,将容量变更为新容量。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -544,6 +584,8 @@ trimToCurrentLength(): void ...@@ -544,6 +584,8 @@ trimToCurrentLength(): void
把容量限制为当前的length大小。 把容量限制为当前的length大小。
**系统能力:** SystemCapability.Utils.Lang
**示例:** **示例:**
```ts ```ts
...@@ -561,6 +603,8 @@ toString(): string ...@@ -561,6 +603,8 @@ toString(): string
用","将Vector实例中的元素按顺序拼接成字符串。 用","将Vector实例中的元素按顺序拼接成字符串。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -584,6 +628,8 @@ copyToArray(array: Array&lt;T&gt;): void ...@@ -584,6 +628,8 @@ copyToArray(array: Array&lt;T&gt;): void
将Vector实例中的元素按照下标复制到指定数组。 将Vector实例中的元素按照下标复制到指定数组。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -608,6 +654,8 @@ getFirstElement(): T ...@@ -608,6 +654,8 @@ getFirstElement(): T
获取实例中的第一个元素。 获取实例中的第一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -631,6 +679,8 @@ getLastElement(): T ...@@ -631,6 +679,8 @@ getLastElement(): T
获取Vector实例中的最后一个元素。 获取Vector实例中的最后一个元素。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
...@@ -654,6 +704,8 @@ getLastIndexFrom(element: T, index: number): number ...@@ -654,6 +704,8 @@ getLastIndexFrom(element: T, index: number): number
从指定索引向后搜索,返回该元素的下标索引。 从指定索引向后搜索,返回该元素的下标索引。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -685,6 +737,8 @@ getIndexFrom(element: T, index: number): number ...@@ -685,6 +737,8 @@ getIndexFrom(element: T, index: number): number
从指定索引向前搜索,返回该元素的下标索引。 从指定索引向前搜索,返回该元素的下标索引。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -716,6 +770,8 @@ setLength(newSize: number): void ...@@ -716,6 +770,8 @@ setLength(newSize: number): void
设置Vector实例的元素个数。 设置Vector实例的元素个数。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -740,6 +796,8 @@ get(index: number): T ...@@ -740,6 +796,8 @@ get(index: number): T
根据下标值获取Vector实例中的元素。 根据下标值获取Vector实例中的元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -768,6 +826,8 @@ set(index: number, element: T): T ...@@ -768,6 +826,8 @@ set(index: number, element: T): T
将此Vector中指定位置的元素替换为指定元素。 将此Vector中指定位置的元素替换为指定元素。
**系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -796,9 +856,10 @@ set(index: number, element: T): T ...@@ -796,9 +856,10 @@ set(index: number, element: T): T
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。
**系统能力:** SystemCapability.Utils.Lang
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册