W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
java.lang.Object
|---ohos.utils.LightweightMap<K,V&
public final class LightweightMap<K,V>
extends Object
implements Map<K,V>
提供一個(gè)實(shí)現(xiàn) Map 接口的容器。
LightweightMap 容器使用的內(nèi)存比 HashMap 容器少,但在達(dá)到較大尺寸時(shí)可能會(huì)表現(xiàn)出較差的性能。
建議您在需要較少內(nèi)存時(shí)使用此容器。
注意:只有從 LightweightMap 容器中讀取數(shù)據(jù)時(shí),線程才是安全的。
從接口 java.util.Map 繼承的嵌套類/接口 |
---|
Map.EntryK,V |
構(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 容器。 |
修飾符和類型 | 方法 | 描述 |
---|---|---|
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 |
從類 java.lang.Object 繼承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
public LightweightMap()
構(gòu)造一個(gè)默認(rèn)的 LightweightMap 容器。
public LightweightMap(int capacity)
構(gòu)造一個(gè)具有指定容量的 LightweightMap 容器。
構(gòu)造的 LightweightMap 容器可以容納的鍵值對(duì)的數(shù)量由指定的容量決定。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
capacity | 表示要構(gòu)建的 LightweightMap 容器的容量。 |
public LightweightMap(int capacity, boolean useIdentityHash)
構(gòu)造一個(gè)指定容量的 LightweightMap 容器,并指定是否使用系統(tǒng)哈希方法。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
capacity | 表示要構(gòu)建的 LightweightMap 容器的容量。 |
useIdentityHash | 指定是否使用系統(tǒng)哈希方法來(lái)映射鍵。 值 true 表示使用 System.identityHashCode 方法。 值 false 表示使用默認(rèn)的 hashCode 方法。 |
public LightweightMap(LightweightMap<? extends K,? extends V> srcLightweightMap)
使用現(xiàn)有 LightweightMap 容器構(gòu)造一個(gè)新的 LightweightMap 容器。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
srcLightweightMap | 指示現(xiàn)有的 LightweightMap 容器。 |
public void clear()
刪除 LightweightMap 容器中的所有鍵值對(duì)映射。
此方法使 LightweightMap 容器為空。
指定者:
在界面 MapK,V 中清除
public boolean containsAll(Collection<?> collection)
檢查 LightweightMap 容器是否具有指定 Collection 對(duì)象中的所有對(duì)象。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
collection | 表示指定的 Collection 對(duì)象。 |
返回:
如果 LightweightMap 容器具有指定 Collection 對(duì)象中的所有對(duì)象,則返回 true; 否則返回 false。
Throws:
Throw名稱 | Throw描述 |
---|---|
NullPointerException | 如果集合為空,則引發(fā)此異常。 |
public boolean containsKey(Object key)
檢查 LightweightMap 容器是否具有與指定鍵相同的鍵。
指定者:
containsKey 在接口 MapK,V
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
key | 表示指定的鍵。 |
返回:
如果 LightweightMap 容器具有與指定鍵相同的鍵,則返回 true; 否則返回 false。
public boolean containsValue(Object value)
檢查 LightweightMap 容器是否具有與指定值相同的值。
指定者:
接口 MapK,V 中的 containsValue
參數(shù):
Parameter Name | Parameter Description |
---|---|
value | Indicates the specified value. |
返回:
如果 LightweightMap 容器的值與指定值相同,則返回 true; 否則返回 false。
public void ensureCapacity(int minimumCapacity)
保證 LightweightMap 容器的容量大于等于指定值,并且容器擴(kuò)容后擁有所有原始對(duì)象。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
minimumCapacity | 指示 LightweightMap 容器允許的最小容量。 |
public SetMap.EntryK,V entrySet()
獲取一個(gè) Set 對(duì)象,該對(duì)象包含 LightweightMap 容器中的所有鍵值對(duì)。
鍵值對(duì)以 Map.Entry 格式存儲(chǔ)。
指定者:
接口 MapK,V 中的 entrySet
返回:
返回一個(gè) Set 對(duì)象,該對(duì)象包含 LightweightMap 容器中的所有鍵值對(duì)。
public V get(Object key)
獲取等于 LightweightMap 容器中指定鍵的值。
指定者:
進(jìn)入接口 MapK,V
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
key | 表示指定的鍵。 |
返回:
返回等于指定鍵的值; 如果指定的鍵在 LightweightMap 容器中不存在,則返回 null。
public int indexOfKey(Object key)
獲取與 LightweightMap 容器中指定鍵相等的鍵的索引。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
key | 表示指定的鍵。 |
返回:
以 int 格式返回請(qǐng)求的索引。
public int indexOfValue(Object value)
獲取 LightweightMap 容器中與指定值相等的值的索引。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
value | 表示指定的值。 |
返回:
以 int 格式返回請(qǐng)求的索引。
public boolean isEmpty()
檢查 LightweightMap 容器是否沒(méi)有鍵值對(duì)。
指定者:
接口 MapK,V 中的 isEmpty
返回:
如果 LightweightMap 容器沒(méi)有鍵值對(duì),則返回 true; 否則返回 false。
public K keyAt(int index)
獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的位置的鍵。
如果 index 為負(fù)數(shù),則從相反方向定位鍵。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
index | 標(biāo)識(shí)密鑰的位置。 |
返回:
返回 LightweightMap 容器中由索引標(biāo)識(shí)的鍵。
public SetK keySet()
獲取包含 LightweightMap 容器的所有鍵的 Set 對(duì)象。
指定者:
接口 MapK,V 中的 keySet
返回:
返回包含 LightweightMap 容器中所有鍵的 Set 對(duì)象。
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ù)名稱 | 參數(shù)描述 |
---|---|
key | 表示要保存的鍵值對(duì)的鍵。 |
value | 表示要保存的鍵值對(duì)的值。 |
返回:
返回執(zhí)行此操作之前鍵的現(xiàn)有值; 如果鍵不包含在 LightweightMap 容器中,則返回 null。
public void putAll(LightweightMap<? extends K,? extends V> arrayMap)
將指定 LightweightMap 容器的所有對(duì)象添加到另一個(gè) LightweightMap 容器。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
arrayMap | 指示將其對(duì)象添加到另一個(gè) LightweightMap 容器的指定 LightweightMap 容器。 |
Throws:
Throw名稱 | Throw描述 |
---|---|
NullPointerException | 如果 arrayMap 為空,則引發(fā)此異常。 |
public void putAll(Map<? extends K,? extends V> map)
將指定 Map 容器的所有對(duì)象添加到 LightweightMap 容器。
指定者:
putAll在接口MapK,V中
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
map | 表示指定的 Map 容器,其對(duì)象將被添加到 LightweightMap 容器中。 |
Throws:
Throw名稱 | Throw描述 |
---|---|
NullPointerException | 如果 map 為 null,則引發(fā)此異常。 |
public V remove(Object key)
從 LightweightMap 容器中刪除與指定鍵相同的鍵值對(duì)。
指定者:
在接口 MapK,V 中移除
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
key | 表示指定的鍵。 |
返回:
如果鍵值對(duì)被刪除,則返回指定鍵的值; 如果鍵不包含在 LightweightMap 容器中,則返回 null。
public boolean removeAll(Collection<?> collection)
從 LightweightMap 容器中刪除與指定 Collection 具有相同對(duì)象的鍵值對(duì)。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
collection | 表示定義要?jiǎng)h除的映射的指定集合。 |
返回:
如果從 LightweightMap 容器中刪除任何對(duì)象,則返回 true; 否則返回 false。
Throws:
Throw名稱 | Throw描述 |
---|---|
NullPointerException | 如果集合為空,則引發(fā)此異常。 |
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ù)名稱 | 參數(shù)描述 |
---|---|
index | 標(biāo)識(shí)鍵值對(duì)的位置。 |
返回:
返回由索引標(biāo)識(shí)的鍵。
public boolean retainAll(Collection<?> collection)
從 LightweightMap 容器中刪除指定 Collection 對(duì)象中不存在的鍵值對(duì)。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
collection | 表示指定的 Collection 對(duì)象。 |
返回:
如果從 LightweightMap 容器中刪除任何鍵值對(duì),則返回 true; 否則返回 false。
Throws:
Throw名稱 | Throw描述 |
---|---|
NullPointerException | 如果集合為空,則引發(fā)此異常。 |
public V setValueAt(int index, V value)
將 LightweightMap 容器中由 index 標(biāo)識(shí)的值設(shè)置為指定值。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
index | 標(biāo)識(shí)值的位置。 |
value | 表示要設(shè)置的值。 |
返回:
返回由索引標(biāo)識(shí)的舊值。
Throws:
Throw名稱 | Throw描述 |
---|---|
IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
public int size()
獲取存儲(chǔ)在 LightweightMap 容器中的鍵值對(duì)的數(shù)量。
指定者:
接口 MapK,V 中的大小
返回:
返回存儲(chǔ)在 LightweightMap 容器中的鍵值對(duì)的數(shù)量。
public String toString()
獲取包含 LightweightMap 容器中所有鍵和值的字符串。
示例字符串是“{1: "one", 2: "two"}"。
鍵和值必須支持 toString 方法。
覆蓋:
類 Object 中的 toString
返回:
返回一個(gè)字符串,其中包含 LightweightMap 容器中的所有鍵和值。
public V valueAt(int index)
獲取 LightweightMap 容器中由 index 標(biāo)識(shí)的值。
如果 index 為負(fù)數(shù),則從反方向定位該值。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
index | 標(biāo)識(shí)值的位置。 |
返回:
返回由索引標(biāo)識(shí)的值。
public CollectionV values()
獲取包含 LightweightMap 容器的所有值的 Collection 對(duì)象。
指定者:
接口 MapK,V 中的值
返回:
返回一個(gè)包含 LightweightMap 容器的所有值的 Collection 對(duì)象。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: