新聞中心
LightweightMap

創(chuàng)新互聯(lián)專(zhuān)注于個(gè)舊網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供個(gè)舊營(yíng)銷(xiāo)型網(wǎng)站建設(shè),個(gè)舊網(wǎng)站制作、個(gè)舊網(wǎng)頁(yè)設(shè)計(jì)、個(gè)舊網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開(kāi)發(fā)服務(wù),打造個(gè)舊網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供個(gè)舊網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
java.lang.Object
|---ohos.utils.LightweightMap
public final class LightweightMap
extends Object
implements Map 提供一個(gè)實(shí)現(xiàn) Map 接口的容器。
LightweightMap 容器使用的內(nèi)存比 HashMap 容器少,但在達(dá)到較大尺寸時(shí)可能會(huì)表現(xiàn)出較差的性能。
建議您在需要較少內(nèi)存時(shí)使用此容器。
注意:只有從 LightweightMap 容器中讀取數(shù)據(jù)時(shí),線程才是安全的。
嵌套類(lèi)摘要
| 從接口 java.util.Map 繼承的嵌套類(lèi)/接口 |
|---|
| Map.EntryK,V |
構(gòu)造函數(shù)摘要
| 構(gòu)造函數(shù) | 描述 |
|---|---|
| LightweightMap() | 構(gòu)造一個(gè)默認(rèn)的 LightweightMap 容器。 |
| LightweightMap(int capacity) | 構(gòu)造一個(gè)具有指定容量的 LightweightMap 容器。 |
| LightweightMap(int capacity, boolean useIdentityHash) | 構(gòu)造一個(gè)指定容量的 LightweightMap 容器,并指定是否使用系統(tǒng)哈希方法。 |
| LightweightMap(LightweightMap extends K,? extends V> srcLightweightMap) | 使用現(xiàn)有 LightweightMap 容器構(gòu)造一個(gè)新的 LightweightMap 容器。 |
方法總結(jié)
| 修飾符和類(lèi)型 | 方法 | 描述 |
|---|---|---|
| void | clear() | 刪除 LightweightMap 容器中的所有鍵值對(duì)映射。 |
| boolean | containsAll(Collection> collection) | 檢查 LightweightMap 容器是否具有指定 Collection 對(duì)象中的所有對(duì)象。 |
| boolean | containsKey(Object key) | 檢查 LightweightMap 容器是否具有與指定鍵相同的鍵。 |
| boolean | containsValue(Object value) | 檢查 LightweightMap 容器是否具有與指定值相同的值。 |
| void | ensureCapacity(int minimumCapacity) | 保證 LightweightMap 容器的容量大于等于指定值,并且容器擴(kuò)容后擁有所有原始對(duì)象。 |
| SetMap.EntryK,V | entrySet() | 獲取一個(gè) Set 對(duì)象,該對(duì)象包含 LightweightMap 容器中的所有鍵值對(duì)。 |
| V | get(Object key) | 獲取等于 LightweightMap 容器中指定鍵的值。 |
| int | indexOfKey(Object key) | 獲取與 LightweightMap 容器中指定鍵相等的鍵的索引。 |
| int | indexOfValue(Object value) | 獲取 LightweightMap 容器中與指定值相等的值的索引。 |
| boolean | isEmpty() | 檢查 LightweightMap 容器是否沒(méi)有鍵值對(duì)。 |
| K | keyAt(int index) | 獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的位置的鍵。 |
| SetK | keySet() | 獲取包含 LightweightMap 容器的所有鍵的 Set 對(duì)象。 |
| V | put(K key, V value) | 將鍵值對(duì)保存到 LightweightMap 容器。 |
| void | putAll(Map extends K,? extends V> map) | 將指定 Map 容器的所有對(duì)象添加到 LightweightMap 容器。 |
| void | putAll(LightweightMap extends K,? extends V> arrayMap) | 將指定 LightweightMap 容器的所有對(duì)象添加到另一個(gè) LightweightMap 容器。 |
| V | remove(Object key) | 從 LightweightMap 容器中刪除與指定鍵相同的鍵值對(duì)。 |
| boolean | removeAll(Collection> collection) | 從 LightweightMap 容器中刪除與指定 Collection 具有相同對(duì)象的鍵值對(duì)。 |
| V | removeAt(int index) | 從 LightweightMap 容器中刪除由 index 標(biāo)識(shí)的位置處的鍵值對(duì)。 |
| boolean | retainAll(Collection> collection) | 從 LightweightMap 容器中刪除指定 Collection 對(duì)象中不存在的鍵值對(duì)。 |
| V | setValueAt(int index, V value) | 將 LightweightMap 容器中由 index 標(biāo)識(shí)的值設(shè)置為指定值。 |
| int | size() | 獲取存儲(chǔ)在 LightweightMap 容器中的鍵值對(duì)的數(shù)量。 |
| String | toString() | 獲取包含 LightweightMap 容器中所有鍵和值的字符串。 |
| V | valueAt(int index) | 獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的值。 |
| CollectionV | values() | 獲取包含 LightweightMap 容器的所有值的 Collection 對(duì)象。 |
| 從接口 java.util.Map 繼承的方法 |
|---|
| compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll |
| 從類(lèi) java.lang.Object 繼承的方法 |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
構(gòu)造函數(shù)詳細(xì)信息
LightweightMap
public LightweightMap()
構(gòu)造一個(gè)默認(rèn)的 LightweightMap 容器。
LightweightMap
public LightweightMap(int capacity)
構(gòu)造一個(gè)具有指定容量的 LightweightMap 容器。
構(gòu)造的 LightweightMap 容器可以容納的鍵值對(duì)的數(shù)量由指定的容量決定。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| capacity | 表示要構(gòu)建的 LightweightMap 容器的容量。 |
LightweightMap
public LightweightMap(int capacity, boolean useIdentityHash)
構(gòu)造一個(gè)指定容量的 LightweightMap 容器,并指定是否使用系統(tǒng)哈希方法。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| capacity | 表示要構(gòu)建的 LightweightMap 容器的容量。 |
| useIdentityHash | 指定是否使用系統(tǒng)哈希方法來(lái)映射鍵。 值 true 表示使用 System.identityHashCode 方法。 值 false 表示使用默認(rèn)的 hashCode 方法。 |
LightweightMap
public LightweightMap(LightweightMap extends K,? extends V> srcLightweightMap)
使用現(xiàn)有 LightweightMap 容器構(gòu)造一個(gè)新的 LightweightMap 容器。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| srcLightweightMap | 指示現(xiàn)有的 LightweightMap 容器。 |
方法詳情
clear
public void clear()
刪除 LightweightMap 容器中的所有鍵值對(duì)映射。
此方法使 LightweightMap 容器為空。
指定者:
在界面 MapK,V 中清除
containsAll
public boolean containsAll(Collection> collection)
檢查 LightweightMap 容器是否具有指定 Collection 對(duì)象中的所有對(duì)象。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| collection | 表示指定的 Collection 對(duì)象。 |
返回:
如果 LightweightMap 容器具有指定 Collection 對(duì)象中的所有對(duì)象,則返回 true; 否則返回 false。
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| NullPointerException | 如果集合為空,則引發(fā)此異常。 |
containsKey
public boolean containsKey(Object key)
檢查 LightweightMap 容器是否具有與指定鍵相同的鍵。
指定者:
containsKey 在接口 MapK,V
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| key | 表示指定的鍵。 |
返回:
如果 LightweightMap 容器具有與指定鍵相同的鍵,則返回 true; 否則返回 false。
containsValue
public boolean containsValue(Object value)
檢查 LightweightMap 容器是否具有與指定值相同的值。
指定者:
接口 MapK,V 中的 containsValue
參數(shù):
| Parameter Name | Parameter Description |
|---|---|
| value | Indicates the specified value. |
返回:
如果 LightweightMap 容器的值與指定值相同,則返回 true; 否則返回 false。
ensureCapacity
public void ensureCapacity(int minimumCapacity)
保證 LightweightMap 容器的容量大于等于指定值,并且容器擴(kuò)容后擁有所有原始對(duì)象。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| minimumCapacity | 指示 LightweightMap 容器允許的最小容量。 |
entrySet
public SetMap.EntryK,V entrySet()
獲取一個(gè) Set 對(duì)象,該對(duì)象包含 LightweightMap 容器中的所有鍵值對(duì)。
鍵值對(duì)以 Map.Entry 格式存儲(chǔ)。
指定者:
接口 MapK,V 中的 entrySet
返回:
返回一個(gè) Set 對(duì)象,該對(duì)象包含 LightweightMap 容器中的所有鍵值對(duì)。
get
public V get(Object key)
獲取等于 LightweightMap 容器中指定鍵的值。
指定者:
進(jìn)入接口 MapK,V
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| key | 表示指定的鍵。 |
返回:
返回等于指定鍵的值; 如果指定的鍵在 LightweightMap 容器中不存在,則返回 null。
indexOfKey
public int indexOfKey(Object key)
獲取與 LightweightMap 容器中指定鍵相等的鍵的索引。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| key | 表示指定的鍵。 |
返回:
以 int 格式返回請(qǐng)求的索引。
indexOfValue
public int indexOfValue(Object value)
獲取 LightweightMap 容器中與指定值相等的值的索引。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| value | 表示指定的值。 |
返回:
以 int 格式返回請(qǐng)求的索引。
isEmpty
public boolean isEmpty()
檢查 LightweightMap 容器是否沒(méi)有鍵值對(duì)。
指定者:
接口 MapK,V 中的 isEmpty
返回:
如果 LightweightMap 容器沒(méi)有鍵值對(duì),則返回 true; 否則返回 false。
keyAt
public K keyAt(int index)
獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的位置的鍵。
如果 index 為負(fù)數(shù),則從相反方向定位鍵。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| index | 標(biāo)識(shí)密鑰的位置。 |
返回:
返回 LightweightMap 容器中由索引標(biāo)識(shí)的鍵。
keySet
public SetK keySet()
獲取包含 LightweightMap 容器的所有鍵的 Set 對(duì)象。
指定者:
接口 MapK,V 中的 keySet
返回:
返回包含 LightweightMap 容器中所有鍵的 Set 對(duì)象。
put
public V put(K key, V value)
將鍵值對(duì)保存到 LightweightMap 容器。
如果 LightweightMap 容器中已經(jīng)存在該鍵值對(duì)的鍵,則該鍵的現(xiàn)有值將被新值覆蓋。
如果 LightweightMap 容器的容量已經(jīng)用完,會(huì)自動(dòng)擴(kuò)容。
指定者:
放入接口 MapK,V
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| key | 表示要保存的鍵值對(duì)的鍵。 |
| value | 表示要保存的鍵值對(duì)的值。 |
返回:
返回執(zhí)行此操作之前鍵的現(xiàn)有值; 如果鍵不包含在 LightweightMap 容器中,則返回 null。
putAll
public void putAll(LightweightMap extends K,? extends V> arrayMap)
將指定 LightweightMap 容器的所有對(duì)象添加到另一個(gè) LightweightMap 容器。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| arrayMap | 指示將其對(duì)象添加到另一個(gè) LightweightMap 容器的指定 LightweightMap 容器。 |
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| NullPointerException | 如果 arrayMap 為空,則引發(fā)此異常。 |
putAll
public void putAll(Map extends K,? extends V> map)
將指定 Map 容器的所有對(duì)象添加到 LightweightMap 容器。
指定者:
putAll在接口MapK,V中
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| map | 表示指定的 Map 容器,其對(duì)象將被添加到 LightweightMap 容器中。 |
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| NullPointerException | 如果 map 為 null,則引發(fā)此異常。 |
remove
public V remove(Object key)
從 LightweightMap 容器中刪除與指定鍵相同的鍵值對(duì)。
指定者:
在接口 MapK,V 中移除
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| key | 表示指定的鍵。 |
返回:
如果鍵值對(duì)被刪除,則返回指定鍵的值; 如果鍵不包含在 LightweightMap 容器中,則返回 null。
removeAll
public boolean removeAll(Collection> collection)
從 LightweightMap 容器中刪除與指定 Collection 具有相同對(duì)象的鍵值對(duì)。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| collection | 表示定義要?jiǎng)h除的映射的指定集合。 |
返回:
如果從 LightweightMap 容器中刪除任何對(duì)象,則返回 true; 否則返回 false。
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| NullPointerException | 如果集合為空,則引發(fā)此異常。 |
removeAt
public V removeAt(int index)
從 LightweightMap 容器中刪除由 index 標(biāo)識(shí)的位置處的鍵值對(duì)。
如果 index 為負(fù)數(shù),則鍵值對(duì)從反方向定位。
在刪除過(guò)程中,系統(tǒng)會(huì)判斷 LightweightMap 容器的容量是擴(kuò)容還是縮容。 如果容器中的對(duì)象數(shù)量小于指定數(shù)量,系統(tǒng)會(huì)減少容器的容量。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| index | 標(biāo)識(shí)鍵值對(duì)的位置。 |
返回:
返回由索引標(biāo)識(shí)的鍵。
retainAll
public boolean retainAll(Collection> collection)
從 LightweightMap 容器中刪除指定 Collection 對(duì)象中不存在的鍵值對(duì)。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| collection | 表示指定的 Collection 對(duì)象。 |
返回:
如果從 LightweightMap 容器中刪除任何鍵值對(duì),則返回 true; 否則返回 false。
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| NullPointerException | 如果集合為空,則引發(fā)此異常。 |
setValueAt
public V setValueAt(int index, V value)
將 LightweightMap 容器中由 index 標(biāo)識(shí)的值設(shè)置為指定值。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| index | 標(biāo)識(shí)值的位置。 |
| value | 表示要設(shè)置的值。 |
返回:
返回由索引標(biāo)識(shí)的舊值。
Throws:
| Throw名稱(chēng) | Throw描述 |
|---|---|
| IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
size
public int size()
獲取存儲(chǔ)在 LightweightMap 容器中的鍵值對(duì)的數(shù)量。
指定者:
接口 MapK,V 中的大小
返回:
返回存儲(chǔ)在 LightweightMap 容器中的鍵值對(duì)的數(shù)量。
toString
public String toString()
獲取包含 LightweightMap 容器中所有鍵和值的字符串。
示例字符串是“{1: "one", 2: "two"}"。
鍵和值必須支持 toString 方法。
覆蓋:
類(lèi) Object 中的 toString
返回:
返回一個(gè)字符串,其中包含 LightweightMap 容器中的所有鍵和值。
valueAt
public V valueAt(int index)
獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的值。
如果 index 為負(fù)數(shù),則從反方向定位該值。
參數(shù):
| 參數(shù)名稱(chēng) | 參數(shù)描述 |
|---|---|
| index | 標(biāo)識(shí)值的位置。 |
返回:
返回由索引標(biāo)識(shí)的值。
values
public CollectionV values()
獲取包含 LightweightMap 容器的所有值的 Collection 對(duì)象。
指定者:
接口 MapK,V 中的值
返回:
返回一個(gè)包含 LightweightMap 容器的所有值的 Collection 對(duì)象。
網(wǎng)頁(yè)標(biāo)題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSLightweightMap
網(wǎng)頁(yè)URL:http://m.fisionsoft.com.cn/article/cogghep.html


咨詢
建站咨詢
