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

!15520 翻译完成:15343+14417 Modify the problem of printing test cases of the...

!15520 翻译完成:15343+14417 Modify the problem of printing test cases of the foreach interface in containers
Merge pull request !15520 from wusongqing/TR15343
......@@ -320,11 +320,9 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.replaceAllElements((value: number, index: number)=> {
return value = 2 * value;
});
arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2;
arrayList.replaceAllElements((value) => {
// Add the user operation logic based on the actual scenario.
return value;
});
```
......@@ -361,7 +359,7 @@ arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -208,7 +208,7 @@ deque.insertEnd(4);
deque.insertFront(5);
deque.insertEnd(4);
deque.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -375,7 +375,7 @@ let hashMap = new HashMap();
hashMap.set("sdfs", 123);
hashMap.set("dfsghsf", 357);
hashMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -228,7 +228,7 @@ let hashSet = new HashSet();
hashSet.add("sdfs");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
hashSet.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -582,7 +582,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("sdfs", 123);
lightWeightMap.set("dfsghsf", 357);
lightWeightMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -482,7 +482,7 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("sdfs");
lightWeightSet.add("dfsghsf");
lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -496,7 +496,7 @@ linkedList.add(4);
linkedList.add(5);
linkedList.add(4);
linkedList.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -405,7 +405,7 @@ list.add(4);
list.add(5);
list.add(4);
list.forEach((value, index) => {
console.log("value: " + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -482,7 +482,7 @@ let plainArray = new PlainArray();
plainArray.add(1, "sddfhf");
plainArray.add(2, "sffdfhf");
plainArray.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -160,7 +160,7 @@ queue.add(4);
queue.add(5);
queue.add(4);
queue.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -192,7 +192,7 @@ stack.push(4);
stack.push(5);
stack.push(4);
stack.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
# Nonlinear Container TreeMap
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**TreeMap** is implemented using a red-black tree, which is a binary search tree where keys are stored in sorted order for efficient insertion and removal.
......@@ -12,6 +8,10 @@
Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -490,7 +490,7 @@ let treeMap = new TreeMap();
treeMap.set("sdfs", 123);
treeMap.set("dfsghsf", 357);
treeMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
# Nonlinear Container TreeSet
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique.
......@@ -10,6 +7,10 @@
Recommended use case: Use **TreeSet** when you need to store data in sorted order.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -392,7 +393,7 @@ let treeSet = new TreeSet();
treeSet.add("sdfs");
treeSet.add("dfsghsf");
treeSet.forEach((value, key) => {
console.log("value:" + value, key)
console.log("value:" + value, "key:" + key);
});
```
......
# Linear Container Vector
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Vector** is a linear data structure that is implemented based on arrays. When the memory of a vector is used up, a larger contiguous memory area is automatically allocated, all the elements are copied to the new memory area, and the current memory area is reclaimed. **Vector** can be used to efficiently access elements.
Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based on arrays, but **Vector** provides more interfaces for operating the arrays. Both of them can dynamically adjust the capacity. **Vector** doubles the capacity each time, whereas **ArrayList** increases the capacity by 50%.
**Recommended use case**: Use **Vector** when the data volume is large.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -248,7 +248,7 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -319,11 +319,9 @@ vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.replaceAllElements((value: number, index: number) => {
return value = 2 * value;
});
vector.replaceAllElements((value: number, index: number) => {
return value = value - 2;
vector.replaceAllElements((value) => {
// Add the user operation logic based on the actual scenario.
return value;
});
```
......@@ -360,7 +358,7 @@ vector.add(4);
vector.add(5);
vector.add(4);
vector.forEach((value, index) => {
console.log("value:" + value, index)
console.log("value:" + value, "index:" + index);
});
```
......@@ -420,7 +418,7 @@ Obtains elements within a range in this container, including the element at the
| -------- | -------- |
| Vector<T> | New **Vector** instance obtained.|
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -442,7 +440,7 @@ Clears all elements in this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -637,18 +635,6 @@ Copies elements in this container into an array to overwrite elements of the sam
| -------- | -------- | -------- | -------- |
| array | Array<T> | Yes| Array to which the elements in the container will be copied.|
**Example**
```ts
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let array = ["a", "b", "c", "d", "e", "f"];
let result = vector.copyToArray(array);
```
### getFirstElement
getFirstElement(): T
......@@ -842,17 +828,6 @@ Replaces an element at the specified position in this container with a given ele
| -------- | -------- |
| T | New element.|
**Example**
```ts
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.set(2, "A");
```
### [Symbol.iterator]
[Symbol.iterator]\(): IterableIterator<T>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册