未验证 提交 a1661cdd 编写于 作者: O openharmony_ci 提交者: Gitee

!10171 翻译完成:9816 modify containers and buffer for vod

Merge pull request !10171 from wusongqing/TR9816
...@@ -12,6 +12,9 @@ When compared with **[LinkedList](js-apis-linkedlist.md)**, **ArrayList** is mor ...@@ -12,6 +12,9 @@ When compared with **[LinkedList](js-apis-linkedlist.md)**, **ArrayList** is mor
**Recommended use case**: Use **ArrayList** when elements in a container need to be frequently read. **Recommended use case**: Use **ArrayList** when elements in a container need to be frequently read.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -72,7 +75,7 @@ Adds an element at the end of this container. ...@@ -72,7 +75,7 @@ Adds an element at the end of this container.
let result1 = arrayList.add(1); let result1 = arrayList.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
let result2 = arrayList.add(b); let result2 = arrayList.add(b);
let c = {name: "lala", age: "13"}; let c = {name: "Dylon", age: "13"};
let result3 = arrayList.add(false); let result3 = arrayList.add(false);
``` ```
...@@ -124,9 +127,9 @@ Checks whether this container has the specified element. ...@@ -124,9 +127,9 @@ Checks whether this container has the specified element.
```ts ```ts
let arrayList = new ArrayList(); let arrayList = new ArrayList();
let result = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = arrayList.has("squirrel");
arrayList.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); arrayList.add("squirrel");
let result1 = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = arrayList.has("squirrel");
``` ```
### getIndexOf ### getIndexOf
...@@ -361,7 +364,7 @@ arrayList.add(4); ...@@ -361,7 +364,7 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.forEach((value, index) => { arrayList.forEach((value, index) => {
console.log("value:" + value, index); console.log(`value:${value}`, index);
}); });
``` ```
...@@ -623,14 +626,14 @@ arrayList.add(4); ...@@ -623,14 +626,14 @@ arrayList.add(4);
// Method 1: // Method 1:
for (let item of arrayList) { for (let item of arrayList) {
console.log("value:" + item); console.log(`value:${item}`);
} }
// Method 2: // Method 2:
let iter = arrayList[Symbol.iterator](); let iter = arrayList[Symbol.iterator]();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
console.log("value:" + temp); console.log(`value:${temp}`);
temp = iter.next().value; temp = iter.next().value;
} }
``` ```
...@@ -12,6 +12,9 @@ Double-ended queue (deque) is a sequence container implemented based on the queu ...@@ -12,6 +12,9 @@ Double-ended queue (deque) is a sequence container implemented based on the queu
**Recommended use case**: Use **Deque** when you need to frequently insert or remove elements at both the ends of a container. **Recommended use case**: Use **Deque** when you need to frequently insert or remove elements at both the ends of a container.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -64,7 +67,7 @@ deque.insertFront("a"); ...@@ -64,7 +67,7 @@ deque.insertFront("a");
deque.insertFront(1); deque.insertFront(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertFront(b); deque.insertFront(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertFront(false); deque.insertFront(false);
``` ```
...@@ -90,7 +93,7 @@ deque.insertEnd("a"); ...@@ -90,7 +93,7 @@ deque.insertEnd("a");
deque.insertEnd(1); deque.insertEnd(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertEnd(b); deque.insertEnd(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertEnd(false); deque.insertEnd(false);
``` ```
...@@ -118,9 +121,9 @@ Checks whether this container has the specified element. ...@@ -118,9 +121,9 @@ Checks whether this container has the specified element.
```ts ```ts
let deque = new Deque(); let deque = new Deque();
let result = deque.has("Ahfbrgrbgnutfodgorrogorg"); let result = deque.has("squirrel");
deque.insertFront("Ahfbrgrbgnutfodgorrogorg"); deque.insertFront("squirrel");
let result1 = deque.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = deque.has("squirrel");
``` ```
### popFirst ### popFirst
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
**Recommended use case**: Use **HashMap** when you need to quickly access, remove, and insert key-value pairs. **Recommended use case**: Use **HashMap** when you need to quickly access, remove, and insert key-value pairs.
This topic uses the following to identify the use of generics:
- K: Key
- V: Value
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -90,9 +94,9 @@ Checks whether this container contains the specified key. ...@@ -90,9 +94,9 @@ Checks whether this container contains the specified key.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashMap.hasKey("squirrel");
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = hashMap.hasKey("squirrel");
``` ```
...@@ -121,7 +125,7 @@ Checks whether this container contains the specified value. ...@@ -121,7 +125,7 @@ Checks whether this container contains the specified value.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.hasValue(123); let result = hashMap.hasValue(123);
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasValue(123); let result1 = hashMap.hasValue(123);
``` ```
...@@ -150,9 +154,9 @@ Obtains the value of the specified key in this container. ...@@ -150,9 +154,9 @@ Obtains the value of the specified key in this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let result = hashMap.get("sdfs"); let result = hashMap.get("sparrow");
``` ```
...@@ -174,8 +178,8 @@ Adds all elements in a **HashMap** instance to this container. ...@@ -174,8 +178,8 @@ Adds all elements in a **HashMap** instance to this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let newHashMap = new HashMap(); let newHashMap = new HashMap();
hashMap.setAll(newHashMap); hashMap.setAll(newHashMap);
``` ```
...@@ -194,7 +198,7 @@ Adds an element to this container. ...@@ -194,7 +198,7 @@ Adds an element to this container.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key of the target element.| | key | K | Yes| Key of the target element.|
| value | V | Yes| Value of the element.| | value | V | Yes| Value of the target element.|
**Return value** **Return value**
...@@ -206,7 +210,7 @@ Adds an element to this container. ...@@ -206,7 +210,7 @@ Adds an element to this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); let result = hashMap.set("squirrel", 123);
``` ```
...@@ -234,9 +238,9 @@ Removes an element with the specified key from this container. ...@@ -234,9 +238,9 @@ Removes an element with the specified key from this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let result = hashMap.remove("sdfs"); let result = hashMap.remove("sparrow");
``` ```
...@@ -252,8 +256,8 @@ Clears this container and sets its length to **0**. ...@@ -252,8 +256,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
hashMap.clear(); hashMap.clear();
``` ```
...@@ -276,8 +280,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -276,8 +280,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.keys(); let iter = hashMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -305,8 +309,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -305,8 +309,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.values(); let iter = hashMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -341,8 +345,8 @@ Replaces an element in this container. ...@@ -341,8 +345,8 @@ Replaces an element in this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("sdfs", 123); hashMap.set("sparrow", 123);
let result = hashMap.replace("sdfs", 357); let result = hashMap.replace("sparrow", 357);
``` ```
...@@ -372,8 +376,8 @@ callbackfn ...@@ -372,8 +376,8 @@ callbackfn
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("sdfs", 123); hashMap.set("sparrow", 123);
hashMap.set("dfsghsf", 357); hashMap.set("gull", 357);
hashMap.forEach((value, key) => { hashMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -398,8 +402,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -398,8 +402,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.entries(); let iter = hashMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -427,8 +431,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -427,8 +431,8 @@ Obtains an iterator, each item of which is a JavaScript object.
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
// Method 1: // Method 1:
for (let item of hashMap) { for (let item of hashMap) {
......
...@@ -10,6 +10,9 @@ Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted o ...@@ -10,6 +10,9 @@ Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted o
**Recommended use case**: Use **HashSet** when you need a set that has only unique elements or need to deduplicate a set. **Recommended use case**: Use **HashSet** when you need a set that has only unique elements or need to deduplicate a set.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -26,6 +29,17 @@ import HashSet from '@ohos.util.HashSet'; ...@@ -26,6 +29,17 @@ import HashSet from '@ohos.util.HashSet';
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of elements in a hash set (called container later).| | length | number | Yes| No| Number of elements in a hash set (called container later).|
**Example**
```ts
let hashSet = new HashSet();
hashSet.add(1);
hashSet.add(2);
hashSet.add(3);
hashSet.add(4);
hashSet.add(5);
let res = hashSet.length;
```
### constructor ### constructor
...@@ -88,9 +102,9 @@ Checks whether this container contains the specified element. ...@@ -88,9 +102,9 @@ Checks whether this container contains the specified element.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
let result = hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashSet.has("squirrel");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
let result1 = hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = hashSet.has("squirrel");
``` ```
...@@ -118,7 +132,7 @@ Adds an element to this container. ...@@ -118,7 +132,7 @@ Adds an element to this container.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
let result = hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashSet.add("squirrel");
``` ```
...@@ -146,9 +160,9 @@ Removes an element from this container. ...@@ -146,9 +160,9 @@ Removes an element from this container.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let result = hashSet.remove("sdfs"); let result = hashSet.remove("sparrow");
``` ```
...@@ -164,8 +178,8 @@ Clears this container and sets its length to **0**. ...@@ -164,8 +178,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
hashSet.clear(); hashSet.clear();
``` ```
...@@ -188,8 +202,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -188,8 +202,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let iter = hashSet.values(); let iter = hashSet.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -225,8 +239,8 @@ callbackfn ...@@ -225,8 +239,8 @@ callbackfn
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("sdfs"); hashSet.add("sparrow");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.forEach((value, key) => { hashSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -250,8 +264,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -250,8 +264,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let iter = hashSet.entries(); let iter = hashSet.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -280,8 +294,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -280,8 +294,8 @@ Obtains an iterator, each item of which is a JavaScript object.
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
// Method 1: // Method 1:
for (let item of hashSet) { for (let item of hashSet) {
......
...@@ -12,6 +12,10 @@ Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs, ...@@ -12,6 +12,10 @@ Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs,
**Recommended use case**: Use LightWeightMap when you need to store and access **KV pairs**. **Recommended use case**: Use LightWeightMap when you need to store and access **KV pairs**.
This topic uses the following to identify the use of generics:
- K: Key
- V: Value
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -92,10 +96,10 @@ Checks whether this container contains all elements of the specified **LightWeig ...@@ -92,10 +96,10 @@ Checks whether this container contains all elements of the specified **LightWeig
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap(); let map = new LightWeightMap();
map.set("sdfs", 356); map.set("sparrow", 356);
let result = lightWeightMap.hasAll(map); let result = lightWeightMap.hasAll(map);
``` ```
...@@ -125,9 +129,9 @@ Checks whether this container contains the specified key. ...@@ -125,9 +129,9 @@ Checks whether this container contains the specified key.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasKey; let result = lightWeightMap.hasKey;
lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightMap.hasKey("squirrel");
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = lightWeightMap.hasKey("squirrel");
``` ```
...@@ -156,7 +160,7 @@ Checks whether this container contains the specified value. ...@@ -156,7 +160,7 @@ Checks whether this container contains the specified value.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasValue(123); let result = lightWeightMap.hasValue(123);
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasValue(123); let result1 = lightWeightMap.hasValue(123);
``` ```
...@@ -207,9 +211,9 @@ Obtains the value of the specified key in this container. ...@@ -207,9 +211,9 @@ Obtains the value of the specified key in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.get("sdfs"); let result = lightWeightMap.get("sparrow");
``` ```
...@@ -237,9 +241,9 @@ Obtains the index of the first occurrence of an element with the specified key i ...@@ -237,9 +241,9 @@ Obtains the index of the first occurrence of an element with the specified key i
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getIndexOfKey("sdfs"); let result = lightWeightMap.getIndexOfKey("sparrow");
``` ```
...@@ -267,8 +271,8 @@ Obtains the index of the first occurrence of an element with the specified value ...@@ -267,8 +271,8 @@ Obtains the index of the first occurrence of an element with the specified value
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getIndexOfValue(123); let result = lightWeightMap.getIndexOfValue(123);
``` ```
...@@ -297,8 +301,8 @@ Obtains the key of an element at the specified position in this container. ...@@ -297,8 +301,8 @@ Obtains the key of an element at the specified position in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getKeyAt(1); let result = lightWeightMap.getKeyAt(1);
``` ```
...@@ -321,8 +325,8 @@ Adds all elements in a **LightWeightMap** instance to this container. ...@@ -321,8 +325,8 @@ Adds all elements in a **LightWeightMap** instance to this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap(); let map = new LightWeightMap();
lightWeightMap.setAll(map); lightWeightMap.setAll(map);
``` ```
...@@ -352,7 +356,7 @@ Adds an element to this container. ...@@ -352,7 +356,7 @@ Adds an element to this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); let result = lightWeightMap.set("squirrel", 123);
``` ```
...@@ -380,9 +384,9 @@ Removes an element with the specified key from this container. ...@@ -380,9 +384,9 @@ Removes an element with the specified key from this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.remove("sdfs"); lightWeightMap.remove("sparrow");
``` ```
...@@ -410,8 +414,8 @@ Removes an element at the specified position from this container. ...@@ -410,8 +414,8 @@ Removes an element at the specified position from this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.removeAt(1); let result = lightWeightMap.removeAt(1);
``` ```
...@@ -441,8 +445,8 @@ Sets a value for an element at the specified position in this container. ...@@ -441,8 +445,8 @@ Sets a value for an element at the specified position in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.setValueAt(1, 3546); lightWeightMap.setValueAt(1, 3546);
``` ```
...@@ -471,8 +475,8 @@ Obtains the value of an element at the specified position in this container. ...@@ -471,8 +475,8 @@ Obtains the value of an element at the specified position in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getValueAt(1); let result = lightWeightMap.getValueAt(1);
``` ```
...@@ -489,8 +493,8 @@ Clears this container and sets its length to **0**. ...@@ -489,8 +493,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.clear(); lightWeightMap.clear();
``` ```
...@@ -513,8 +517,8 @@ Obtains an iterator that contains all the keys in this container. ...@@ -513,8 +517,8 @@ Obtains an iterator that contains all the keys in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.keys(); let iter = lightWeightMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -542,8 +546,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -542,8 +546,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.values(); let iter = lightWeightMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -579,8 +583,8 @@ callbackfn ...@@ -579,8 +583,8 @@ callbackfn
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("sdfs", 123); lightWeightMap.set("sparrow", 123);
lightWeightMap.set("dfsghsf", 357); lightWeightMap.set("gull", 357);
lightWeightMap.forEach((value, key) => { lightWeightMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -605,8 +609,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -605,8 +609,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.entries(); let iter = lightWeightMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -634,8 +638,8 @@ Concatenates the elements in this container into a string and returns the string ...@@ -634,8 +638,8 @@ Concatenates the elements in this container into a string and returns the string
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("A", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.toString(); let iter = lightWeightMap.toString();
``` ```
...@@ -657,8 +661,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -657,8 +661,8 @@ Obtains an iterator, each item of which is a JavaScript object.
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
// Method 1: // Method 1:
for (let item of lightWeightMap) { for (let item of lightWeightMap) {
......
...@@ -14,6 +14,9 @@ Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, ** ...@@ -14,6 +14,9 @@ Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, **
**Recommended use case**: Use **LightWeightSet** when you need a set that has only unique elements or need to deduplicate a set. **Recommended use case**: Use **LightWeightSet** when you need a set that has only unique elements or need to deduplicate a set.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -93,7 +96,7 @@ Adds an element to this container. ...@@ -93,7 +96,7 @@ Adds an element to this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = lightWeightSet.add("squirrel");
``` ```
...@@ -115,10 +118,10 @@ Adds all elements in a **LightWeightSet** instance to this container. ...@@ -115,10 +118,10 @@ Adds all elements in a **LightWeightSet** instance to this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("sfage"); set.add("gull");
let result = lightWeightSet.addAll(set); let result = lightWeightSet.addAll(set);
``` ```
...@@ -147,10 +150,10 @@ Checks whether this container contains all elements of the specified **LightWeig ...@@ -147,10 +150,10 @@ Checks whether this container contains all elements of the specified **LightWeig
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("sdfs"); set.add("sparrow");
let result = lightWeightSet.hasAll(set); let result = lightWeightSet.hasAll(set);
``` ```
...@@ -209,9 +212,9 @@ Checks whether this container contains objects of the same type as the specified ...@@ -209,9 +212,9 @@ Checks whether this container contains objects of the same type as the specified
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let obj = ["Ahfbrgrbgnutfodgorrogorgrogofdfdf", "sdfs"]; let obj = ["squirrel", "sparrow"];
let result = lightWeightSet.equal(obj); let result = lightWeightSet.equal(obj);
``` ```
...@@ -262,9 +265,9 @@ Obtains the position index of the element with the specified key in this contain ...@@ -262,9 +265,9 @@ Obtains the position index of the element with the specified key in this contain
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getIndexOf("sdfs"); let result = lightWeightSet.getIndexOf("sparrow");
``` ```
...@@ -292,9 +295,9 @@ Removes an element of the specified key from this container. ...@@ -292,9 +295,9 @@ Removes an element of the specified key from this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.remove("sdfs"); let result = lightWeightSet.remove("sparrow");
``` ```
...@@ -322,8 +325,8 @@ Removes the element at the specified position from this container. ...@@ -322,8 +325,8 @@ Removes the element at the specified position from this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.removeAt(1); let result = lightWeightSet.removeAt(1);
``` ```
...@@ -352,8 +355,8 @@ Obtains the value of the element at the specified position in this container. ...@@ -352,8 +355,8 @@ Obtains the value of the element at the specified position in this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getValueAt(1); let result = lightWeightSet.getValueAt(1);
``` ```
...@@ -370,8 +373,8 @@ Clears this container and sets its length to **0**. ...@@ -370,8 +373,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
lightWeightSet.clear(); lightWeightSet.clear();
``` ```
...@@ -394,8 +397,8 @@ Obtains a string that contains all elements in this container. ...@@ -394,8 +397,8 @@ Obtains a string that contains all elements in this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toString(); let result = lightWeightSet.toString();
``` ```
...@@ -418,8 +421,8 @@ Obtains an array that contains all objects in this container. ...@@ -418,8 +421,8 @@ Obtains an array that contains all objects in this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toArray(); let result = lightWeightSet.toArray();
``` ```
...@@ -442,8 +445,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -442,8 +445,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let iter = lightWeightSet.values(); let iter = lightWeightSet.values();
let index = 0; let index = 0;
while(index < lightWeightSet.length) { while(index < lightWeightSet.length) {
...@@ -479,8 +482,8 @@ callbackfn ...@@ -479,8 +482,8 @@ callbackfn
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
lightWeightSet.add("dfsghsf"); lightWeightSet.add("gull");
lightWeightSet.forEach((value, key) => { lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -505,8 +508,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -505,8 +508,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let iter = lightWeightSet.entries(); let iter = lightWeightSet.entries();
let index = 0; let index = 0;
while(index < lightWeightSet.length) { while(index < lightWeightSet.length) {
...@@ -534,8 +537,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -534,8 +537,8 @@ Obtains an iterator, each item of which is a JavaScript object.
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
// Method 1: // Method 1:
for (let item of lightWeightSet) { for (let item of lightWeightSet) {
......
...@@ -12,6 +12,9 @@ Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList* ...@@ -12,6 +12,9 @@ Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList*
**Recommended use case**: Use **LinkedList** for frequent insertion and removal operations. **Recommended use case**: Use **LinkedList** for frequent insertion and removal operations.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -76,7 +79,7 @@ let result = linkedList.add("a"); ...@@ -76,7 +79,7 @@ let result = linkedList.add("a");
let result1 = linkedList.add(1); let result1 = linkedList.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.add(b); linkedList.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = linkedList.add(false); let result3 = linkedList.add(false);
``` ```
...@@ -102,7 +105,7 @@ linkedList.addFirst("a"); ...@@ -102,7 +105,7 @@ linkedList.addFirst("a");
linkedList.addFirst(1); linkedList.addFirst(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.addFirst(b); linkedList.addFirst(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
linkedList.addFirst(false); linkedList.addFirst(false);
``` ```
...@@ -154,9 +157,9 @@ Checks whether this container has the specified element. ...@@ -154,9 +157,9 @@ Checks whether this container has the specified element.
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
let result1 = linkedList.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = linkedList.has("squirrel");
linkedList.add("Ahfbrgrbgnutfodgorrogorg"); linkedList.add("squirrel");
let result = linkedList.has("Ahfbrgrbgnutfodgorrogorg"); let result = linkedList.has("squirrel");
``` ```
### get ### get
......
...@@ -10,6 +10,9 @@ Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **Lis ...@@ -10,6 +10,9 @@ Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **Lis
**Recommended use case**: Use **List** for frequent insertion and removal operations. **Recommended use case**: Use **List** for frequent insertion and removal operations.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -72,7 +75,7 @@ let result = list.add("a"); ...@@ -72,7 +75,7 @@ let result = list.add("a");
let result1 = list.add(1); let result1 = list.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
list.add(b); list.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = list.add(false); let result3 = list.add(false);
``` ```
...@@ -124,9 +127,9 @@ Checks whether this container has the specified element. ...@@ -124,9 +127,9 @@ Checks whether this container has the specified element.
```ts ```ts
let list = new List(); let list = new List();
let result = list.has("Ahfbrgrbgnutfodgorrogorg"); let result = list.has("squirrel");
list.add("Ahfbrgrbgnutfodgorrogorg"); list.add("squirrel");
let result1 = list.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = list.has("squirrel");
``` ```
### get ### get
...@@ -181,7 +184,7 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -181,7 +184,7 @@ Obtains the index of the last occurrence of the specified element in this contai
| Value Type | Description| | Value Type | Description|
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the index if obtained; returns **-1** otherwise.|
**Example** **Example**
...@@ -265,7 +268,7 @@ obj1.add(2); ...@@ -265,7 +268,7 @@ obj1.add(2);
obj1.add(4); obj1.add(4);
obj1.add(5); obj1.add(5);
list.equal(obj1); list.equal(obj1);
let obj2 = {name : "lala", age : "13"}; let obj2 = {name : "Dylon", age : "13"};
let result = list.equal(obj2); let result = list.equal(obj2);
``` ```
......
...@@ -12,6 +12,9 @@ Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used ...@@ -12,6 +12,9 @@ Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used
**Recommended use case**: Use **PlainArray** when you need to store KV pairs whose keys are of the **number** type. **Recommended use case**: Use **PlainArray** when you need to store KV pairs whose keys are of the **number** type.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -93,7 +96,7 @@ Checks whether this container contains the specified key. ...@@ -93,7 +96,7 @@ Checks whether this container contains the specified key.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.has(1); plainArray.has(1);
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
let result1 = plainArray.has(1); let result1 = plainArray.has(1);
``` ```
...@@ -122,8 +125,8 @@ Obtains the value of the specified key in this container. ...@@ -122,8 +125,8 @@ Obtains the value of the specified key in this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.get(1); let result = plainArray.get(1);
``` ```
...@@ -152,8 +155,8 @@ Obtains the index of the first occurrence of an element with the specified key i ...@@ -152,8 +155,8 @@ Obtains the index of the first occurrence of an element with the specified key i
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfKey(2); let result = plainArray.getIndexOfKey(2);
``` ```
...@@ -182,9 +185,9 @@ Obtains the index of the first occurrence of an element with the specified value ...@@ -182,9 +185,9 @@ Obtains the index of the first occurrence of an element with the specified value
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfValue("sddfhf"); let result = plainArray.getIndexOfValue("squirrel");
``` ```
...@@ -212,8 +215,8 @@ Obtains the key of the element at the specified position in this container. ...@@ -212,8 +215,8 @@ Obtains the key of the element at the specified position in this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getKeyAt(1);
``` ```
...@@ -241,8 +244,8 @@ Obtains the value of an element at the specified position in this container. ...@@ -241,8 +244,8 @@ Obtains the value of an element at the specified position in this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getKeyAt(1);
``` ```
...@@ -264,8 +267,8 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -264,8 +267,8 @@ Clones this container and returns a copy. The modification to the copy does not
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let newPlainArray = plainArray.clone(); let newPlainArray = plainArray.clone();
``` ```
...@@ -289,7 +292,7 @@ Adds an element to this container. ...@@ -289,7 +292,7 @@ Adds an element to this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
``` ```
...@@ -317,8 +320,8 @@ Removes an element with the specified key from this container. ...@@ -317,8 +320,8 @@ Removes an element with the specified key from this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.remove(2); plainArray.remove(2);
let result = plainArray.remove(2); let result = plainArray.remove(2);
``` ```
...@@ -348,8 +351,8 @@ Removes an element at the specified position from this container. ...@@ -348,8 +351,8 @@ Removes an element at the specified position from this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.removeAt(1); plainArray.removeAt(1);
let result = plainArray.removeAt(1); let result = plainArray.removeAt(1);
``` ```
...@@ -380,8 +383,8 @@ Removes elements in a specified range from this container. ...@@ -380,8 +383,8 @@ Removes elements in a specified range from this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.removeRangeFrom(1, 3); let result = plainArray.removeRangeFrom(1, 3);
``` ```
...@@ -405,8 +408,8 @@ Sets a value for an element at the specified position in this container. ...@@ -405,8 +408,8 @@ Sets a value for an element at the specified position in this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.setValueAt(1, 3546); plainArray.setValueAt(1, 3546);
``` ```
...@@ -429,8 +432,8 @@ Obtains a string that contains all elements in this container. ...@@ -429,8 +432,8 @@ Obtains a string that contains all elements in this container.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.toString(); let result = plainArray.toString();
``` ```
...@@ -447,8 +450,8 @@ Clears this container and sets its length to **0**. ...@@ -447,8 +450,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.clear(); plainArray.clear();
``` ```
...@@ -479,8 +482,8 @@ callbackfn ...@@ -479,8 +482,8 @@ callbackfn
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.forEach((value, index) => { plainArray.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
...@@ -505,8 +508,8 @@ Obtains an iterator object that contains key-value pairs, where the key is of th ...@@ -505,8 +508,8 @@ Obtains an iterator object that contains key-value pairs, where the key is of th
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
// Method 1: // Method 1:
for (let item of plainArray) { for (let item of plainArray) {
......
...@@ -10,6 +10,9 @@ Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at bo ...@@ -10,6 +10,9 @@ Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at bo
**Recommended use case**: Use **Queue** in FIFO scenarios. **Recommended use case**: Use **Queue** in FIFO scenarios.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -72,7 +75,7 @@ let result1 = queue.add(1); ...@@ -72,7 +75,7 @@ let result1 = queue.add(1);
queue.add(1); queue.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
queue.add(b); queue.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = queue.add(c); let result3 = queue.add(c);
``` ```
...@@ -180,6 +183,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -180,6 +183,7 @@ Obtains an iterator, each item of which is a JavaScript object.
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Example** **Example**
```ts ```ts
let queue = new Queue(); let queue = new Queue();
queue.add(2); queue.add(2);
......
...@@ -10,6 +10,9 @@ Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue da ...@@ -10,6 +10,9 @@ Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue da
**Recommended use case**: Use **Stack** in LOFI scenarios. **Recommended use case**: Use **Stack** in LOFI scenarios.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -73,7 +76,7 @@ let result = stack.push("a"); ...@@ -73,7 +76,7 @@ let result = stack.push("a");
let result1 = stack.push(1); let result1 = stack.push(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
stack.push(b); stack.push(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = stack.push(c); let result3 = stack.push(c);
``` ```
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order. Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order.
This topic uses the following to identify the use of generics:
- K: Key
- V: Value
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -96,9 +100,9 @@ Checks whether this container has the specified key. ...@@ -96,9 +100,9 @@ Checks whether this container has the specified key.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
let result = treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = treeMap.hasKey("squirrel");
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
let result1 = treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = treeMap.hasKey("squirrel");
``` ```
...@@ -127,7 +131,7 @@ Checks whether this container has the specified value. ...@@ -127,7 +131,7 @@ Checks whether this container has the specified value.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
let result = treeMap.hasValue(123); let result = treeMap.hasValue(123);
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
let result1 = treeMap.hasValue(123); let result1 = treeMap.hasValue(123);
``` ```
...@@ -156,9 +160,9 @@ Obtains the value of the specified key in this container. ...@@ -156,9 +160,9 @@ Obtains the value of the specified key in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.get("sdfs"); let result = treeMap.get("sparrow");
``` ```
...@@ -180,8 +184,8 @@ Obtains the first key in this container. ...@@ -180,8 +184,8 @@ Obtains the first key in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.getFirstKey(); let result = treeMap.getFirstKey();
``` ```
...@@ -204,8 +208,8 @@ Obtains the last key in this container. ...@@ -204,8 +208,8 @@ Obtains the last key in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.getLastKey(); let result = treeMap.getLastKey();
``` ```
...@@ -228,8 +232,8 @@ Adds all elements in a **TreeMap** instance to this container. ...@@ -228,8 +232,8 @@ Adds all elements in a **TreeMap** instance to this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let map = new TreeMap(); let map = new TreeMap();
treeMap.setAll(map); treeMap.setAll(map);
``` ```
...@@ -260,7 +264,7 @@ Adds an element to this container. ...@@ -260,7 +264,7 @@ Adds an element to this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
``` ```
...@@ -288,9 +292,9 @@ Removes the element with the specified key from this container. ...@@ -288,9 +292,9 @@ Removes the element with the specified key from this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.remove("sdfs"); treeMap.remove("sparrow");
``` ```
...@@ -318,10 +322,10 @@ Obtains the key that is placed in front of the input key in this container. ...@@ -318,10 +322,10 @@ Obtains the key that is placed in front of the input key in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.set("zdfgsd", 356); treeMap.set("gander", 356);
let result = treeMap.getLowerKey("sdfs"); let result = treeMap.getLowerKey("sparrow");
``` ```
...@@ -349,10 +353,10 @@ Obtains the key that is placed next to the input key in this container. ...@@ -349,10 +353,10 @@ Obtains the key that is placed next to the input key in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.set("zdfgsd", 356); treeMap.set("gander", 356);
let result = treeMap.getHigherKey("sdfs"); let result = treeMap.getHigherKey("sparrow");
``` ```
### replace ### replace
...@@ -380,8 +384,8 @@ Replaces an element in this container. ...@@ -380,8 +384,8 @@ Replaces an element in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("sdfs", 123); treeMap.set("sparrow", 123);
let result = treeMap.replace("sdfs", 357); let result = treeMap.replace("sparrow", 357);
``` ```
...@@ -397,8 +401,8 @@ Clears this container and sets its length to **0**. ...@@ -397,8 +401,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.clear(); treeMap.clear();
``` ```
...@@ -421,8 +425,8 @@ Obtains an iterator that contains all the keys in this container. ...@@ -421,8 +425,8 @@ Obtains an iterator that contains all the keys in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.keys(); let iter = treeMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -450,8 +454,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -450,8 +454,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.values(); let iter = treeMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -487,8 +491,8 @@ callbackfn ...@@ -487,8 +491,8 @@ callbackfn
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("sdfs", 123); treeMap.set("sparrow", 123);
treeMap.set("dfsghsf", 357); treeMap.set("gull", 357);
treeMap.forEach((value, key) => { treeMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -513,8 +517,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -513,8 +517,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.entries(); let iter = treeMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -542,8 +546,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -542,8 +546,8 @@ Obtains an iterator, each item of which is a JavaScript object.
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
// Method 1: // Method 1:
for (let item of treeMap) { for (let item of treeMap) {
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
Recommended use case: Use **TreeSet** when you need to store data in sorted order. Recommended use case: Use **TreeSet** when you need to store data in sorted order.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -29,7 +32,7 @@ import TreeSet from '@ohos.util.TreeSet'; ...@@ -29,7 +32,7 @@ import TreeSet from '@ohos.util.TreeSet';
### constructor ### constructor
constructor(comparator?:(firstValue: T, secondValue: T) => boolean) constructor(comparator?: (firstValue: T, secondValue: T) => boolean)
A constructor used to create a **TreeSet** instance. A constructor used to create a **TreeSet** instance.
...@@ -118,8 +121,8 @@ Obtains the value of the first element in this container. ...@@ -118,8 +121,8 @@ Obtains the value of the first element in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.getFirstValue(); let result = treeSet.getFirstValue();
``` ```
...@@ -142,8 +145,8 @@ Obtains the value of the last element in this container. ...@@ -142,8 +145,8 @@ Obtains the value of the last element in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.getLastValue(); let result = treeSet.getLastValue();
``` ```
...@@ -172,7 +175,7 @@ Adds an element to this container. ...@@ -172,7 +175,7 @@ Adds an element to this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
let result = treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = treeSet.add("squirrel");
``` ```
...@@ -200,9 +203,9 @@ Removes the element with the specified key from this container. ...@@ -200,9 +203,9 @@ Removes the element with the specified key from this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.remove("sdfs"); let result = treeSet.remove("sparrow");
``` ```
...@@ -230,10 +233,10 @@ Obtains the value that is placed in front of the input key in this container. ...@@ -230,10 +233,10 @@ Obtains the value that is placed in front of the input key in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("zdfgsd"); treeSet.add("gander");
let result = treeSet.getLowerValue("sdfs"); let result = treeSet.getLowerValue("sparrow");
``` ```
...@@ -261,10 +264,10 @@ Obtains the value that is placed next to the input key in this container. ...@@ -261,10 +264,10 @@ Obtains the value that is placed next to the input key in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("zdfgsd"); treeSet.add("gander");
let result = treeSet.getHigherValue("sdfs"); let result = treeSet.getHigherValue("sparrow");
``` ```
...@@ -286,8 +289,8 @@ Removes the first element in this container. ...@@ -286,8 +289,8 @@ Removes the first element in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.popFirst(); let result = treeSet.popFirst();
``` ```
...@@ -310,8 +313,8 @@ Removes the last element in this container. ...@@ -310,8 +313,8 @@ Removes the last element in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.popLast(); let result = treeSet.popLast();
``` ```
...@@ -328,8 +331,8 @@ Clears this container and sets its length to **0**. ...@@ -328,8 +331,8 @@ Clears this container and sets its length to **0**.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.clear(); treeSet.clear();
``` ```
...@@ -352,8 +355,8 @@ Obtains an iterator that contains all the values in this container. ...@@ -352,8 +355,8 @@ Obtains an iterator that contains all the values in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let iter = treeSet.values(); let iter = treeSet.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -389,8 +392,8 @@ callbackfn ...@@ -389,8 +392,8 @@ callbackfn
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("dfsghsf"); treeSet.add("gull");
treeSet.forEach((value, key) => { treeSet.forEach((value, key) => {
console.log("value:" + value, key) console.log("value:" + value, key)
}); });
...@@ -415,8 +418,8 @@ Obtains an iterator that contains all the elements in this container. ...@@ -415,8 +418,8 @@ Obtains an iterator that contains all the elements in this container.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let iter = treeSet.entries(); let iter = treeSet.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -445,8 +448,8 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -445,8 +448,8 @@ Obtains an iterator, each item of which is a JavaScript object.
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
// Method 1: // Method 1:
for (let item of treeSet) { for (let item of treeSet) {
......
...@@ -10,6 +10,9 @@ Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based ...@@ -10,6 +10,9 @@ Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based
**Recommended use case**: Use **Vector** when the data volume is large. **Recommended use case**: Use **Vector** when the data volume is large.
This topic uses the following to identify the use of generics:
- T: Type
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -71,7 +74,7 @@ let result = vector.add("a"); ...@@ -71,7 +74,7 @@ let result = vector.add("a");
let result1 = vector.add(1); let result1 = vector.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
vector.add(b); vector.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = vector.add(c); let result3 = vector.add(c);
``` ```
...@@ -123,9 +126,9 @@ Checks whether this container has the specified element. ...@@ -123,9 +126,9 @@ Checks whether this container has the specified element.
```ts ```ts
let vector = new Vector(); let vector = new Vector();
let result = vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = vector.has("squirrel");
vector.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); vector.add("squirrel");
let result1 = vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = vector.has("squirrel");
``` ```
### getIndexOf ### getIndexOf
...@@ -862,7 +865,6 @@ Obtains an iterator. Each item of the iterator is a JavaScript object. ...@@ -862,7 +865,6 @@ Obtains an iterator. Each item of the iterator is a JavaScript object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册