新聞中心
PlainBooleanArray

創(chuàng)新互聯(lián)為企業(yè)級(jí)客戶提高一站式互聯(lián)網(wǎng)+設(shè)計(jì)服務(wù),主要包括網(wǎng)站建設(shè)、做網(wǎng)站、成都App定制開(kāi)發(fā)、微信平臺(tái)小程序開(kāi)發(fā)、宣傳片制作、LOGO設(shè)計(jì)等,幫助客戶快速提升營(yíng)銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經(jīng)驗(yàn)豐富的經(jīng)驗(yàn),可以確保每一個(gè)作品的質(zhì)量和創(chuàng)作周期,同時(shí)每年都有很多新員工加入,為我們帶來(lái)大量新的創(chuàng)意。
java.lang.Object
|---ohos.utils.PlainBooleanArray
public class PlainBooleanArray
extends Object
implements Cloneable
一個(gè)基本的集合類,用于存儲(chǔ)使用原始數(shù)據(jù)類型 int 作為鍵和 boolean 作為值的數(shù)據(jù)結(jié)構(gòu)。
此類中的值直接存儲(chǔ)在數(shù)組中,無(wú)需包裝到其他類型或自動(dòng)裝箱。 這簡(jiǎn)化了數(shù)據(jù)存儲(chǔ)結(jié)構(gòu)并節(jié)省了內(nèi)存。 該類中的所有key在存儲(chǔ)時(shí)都是按升序排序的,使用二分查找算法高效查找指定key。 在這樣的數(shù)據(jù)存儲(chǔ)結(jié)構(gòu)中,鍵和值可以基于索引進(jìn)行迭代。 這個(gè)類實(shí)現(xiàn)了 Cloneable 接口。
使用 PlainBooleanArray 類時(shí)要注意以下幾點(diǎn):
- 這個(gè)類是非線程安全的。
- 值的存儲(chǔ)順序與插入時(shí)不同。
字段摘要
| 修飾符和類型 | 字段 | 描述 |
|---|---|---|
| static int | INVALID_INDEX | 指示索引相關(guān)操作使用的無(wú)效索引。 |
構(gòu)造函數(shù)摘要
| 構(gòu)造函數(shù) | 描述 |
|---|---|
| PlainBooleanArray() | 用于創(chuàng)建 PlainBooleanArray 實(shí)例的默認(rèn)構(gòu)造函數(shù)。 |
| PlainBooleanArray(int capacity) | 用于創(chuàng)建具有自定義初始容量的 PlainBooleanArray 實(shí)例的構(gòu)造函數(shù)。 |
方法總結(jié)
| 修飾符和類型 | 方法 | 描述 |
|---|---|---|
| void | append(int key, boolean value) | 將鍵值對(duì)附加到 PlainBooleanArray。 |
| void | clear() | 清除存儲(chǔ)在當(dāng)前 PlainBooleanArray 對(duì)象中的所有鍵值對(duì)。 |
| PlainBooleanArray | clone() | 創(chuàng)建當(dāng)前 PlainBooleanArray 對(duì)象的克隆。 |
| boolean | contains(int key) | 檢查當(dāng)前的 PlainBooleanArray 對(duì)象是否包含指定的鍵。 |
| OptionalBoolean | get(int key) | 查詢與指定鍵關(guān)聯(lián)的值。 |
| boolean | get(int key, boolean defaultValue) | 使用傳遞的 defaultValue 參數(shù)查詢與指定鍵關(guān)聯(lián)的值。 |
| int | indexOfKey(int key) | 查詢指定鍵的索引。 |
| int | indexOfValue(boolean value) | 查詢指定值的索引。 |
| boolean | isEmpty() | 檢查當(dāng)前的 PlainBooleanArray 對(duì)象是否為空。 |
| int | keyAt(int index) | 查詢指定索引處的鍵。 |
| int | locate(int key) | 搜索指定鍵的索引。 |
| void | put(int key, boolean value) | 將鍵值對(duì)添加到 PlainBooleanArray。 |
| OptionalBoolean | remove(int key) | 根據(jù)指定鍵刪除鍵值對(duì)。 |
| OptionalBoolean | removeAt(int index) | 刪除指定索引處的鍵值對(duì)。 |
| void | setValueAt(int index, boolean value) | 更新指定索引處的值。 |
| int | size() | 獲取當(dāng)前 PlainBooleanArray 中存儲(chǔ)的值的總數(shù)。 |
| String | toString() | 獲取 PlainBooleanArray 對(duì)象的字符串表示形式。 |
| boolean | valueAt(int index) | 查詢指定索引處的值。 |
| 從類 java.lang.Object 繼承的方法 |
|---|
| equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
字段詳細(xì)信息
INVALID_INDEX
public static final int INVALID_INDEX
指示索引相關(guān)操作使用的無(wú)效索引。
構(gòu)造函數(shù)詳細(xì)信息
PlainBooleanArray
public PlainBooleanArray()
用于創(chuàng)建 PlainBooleanArray 實(shí)例的默認(rèn)構(gòu)造函數(shù)。
PlainBooleanArray
public PlainBooleanArray(int capacity)
用于創(chuàng)建具有自定義初始容量的 PlainBooleanArray 實(shí)例的構(gòu)造函數(shù)。
此構(gòu)造函數(shù)允許您自定義 PlainBooleanArray 對(duì)象的初始容量。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| capacity | 指示要為對(duì)象自定義的初始容量。 |
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IllegalArgumentException | 如果指定的容量小于或等于 0,則引發(fā)此異常。 |
方法詳情
locate
public int locate(int key)
搜索指定鍵的索引。
二分搜索算法用于搜索。 如果沒(méi)有找到結(jié)果,則返回負(fù)值。 但是,您可以將此負(fù)值取反以獲取該鍵應(yīng)存儲(chǔ)在數(shù)組中的索引。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要搜索的鍵。 |
返回:
返回鍵的索引; 如果沒(méi)有找到結(jié)果,則返回負(fù)值。
append
public void append(int key, boolean value)
將鍵值對(duì)附加到 PlainBooleanArray。
如果要添加的鍵大于數(shù)組中的任何現(xiàn)有鍵,則此方法比 put(int,boolean) 方法更有效。 如果指定的鍵不是數(shù)組中最大的鍵,則自動(dòng)調(diào)用 put(int,boolean) 方法添加鍵值對(duì)。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要添加的鍵。 |
| value | 指示與鍵關(guān)聯(lián)的值。 |
clear
public void clear()
清除存儲(chǔ)在當(dāng)前 PlainBooleanArray 對(duì)象中的所有鍵值對(duì)。
clone
public PlainBooleanArray clone()
創(chuàng)建當(dāng)前 PlainBooleanArray 對(duì)象的克隆。
覆蓋:
在類 Object 中克隆
返回:
返回 PlainBooleanArray 對(duì)象的克隆。
get
public OptionalBoolean get(int key)
查詢與指定鍵關(guān)聯(lián)的值。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要查詢的值的鍵。 |
返回:
返回一個(gè)包含獲得值的 Optional 對(duì)象; 如果 key 不存在,則返回一個(gè)空的 Optional 對(duì)象。
get
public boolean get(int key, boolean defaultValue)
使用傳遞的 defaultValue 參數(shù)查詢與指定鍵關(guān)聯(lián)的值。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要查詢的值的鍵。 |
| defaultValue | 表示默認(rèn)值。 |
返回:
返回鍵的值; 如果鍵不存在,則返回 defaultValue。
indexOfKey
public int indexOfKey(int key)
查詢指定鍵的索引。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要查詢的鍵。 |
返回:
返回鍵的索引; 如果查詢的鍵不存在,則返回 INVALID_INDEX。
indexOfValue
public int indexOfValue(boolean value)
查詢指定值的索引。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| value | 表示要查詢的值。 |
返回:
如果找到多個(gè)值,則返回第一個(gè)匹配值的索引; 如果查詢的值不存在,則返回 INVALID_INDEX。
keyAt
public int keyAt(int index)
查詢指定索引處的鍵。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| index | 表示要查詢的索引。 |
返回:
返回指定索引處的鍵。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
valueAt
public boolean valueAt(int index)
查詢指定索引處的值。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| index | 表示要查詢的索引。 |
返回:
返回指定索引處的值。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
put
public void put(int key, boolean value)
將鍵值對(duì)添加到 PlainBooleanArray。
如果指定的鍵已經(jīng)存在,它的值將被替換為值。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要添加的鍵。 |
| value | 指示與鍵關(guān)聯(lián)的值。 |
setValueAt
public void setValueAt(int index, boolean value)
更新指定索引處的值。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| index | 指示要更新的值的索引。 |
| value | 表示新值。 |
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
remove
public OptionalBoolean remove(int key)
根據(jù)指定鍵刪除鍵值對(duì)。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要?jiǎng)h除的密鑰。 |
返回:
返回一個(gè)包含已移除值的 Optional 對(duì)象; 如果 key 不存在,則返回一個(gè)空的 Optional 對(duì)象。
removeAt
public OptionalBoolean removeAt(int index)
刪除指定索引處的鍵值對(duì)。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| index | 表示要移除的鍵值對(duì)的索引。 |
返回:
返回包含已刪除值的 Optional 對(duì)象。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IndexOutOfBoundsException | 如果指定的索引超出有效范圍,則引發(fā)此異常。 |
size
public int size()
獲取當(dāng)前 PlainBooleanArray 中存儲(chǔ)的值的總數(shù)。
返回:
返回存儲(chǔ)值的總數(shù)。
isEmpty
public boolean isEmpty()
檢查當(dāng)前的 PlainBooleanArray 對(duì)象是否為空。
返回:
如果不包含任何值,則返回 true; 否則返回 false。
contains
public boolean contains(int key)
檢查當(dāng)前的 PlainBooleanArray 對(duì)象是否包含指定的鍵。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| key | 表示要檢查的鍵。 |
返回:
如果指定的鍵存在,則返回 true; 否則返回 false。
toString
public String toString()
獲取 PlainBooleanArray 對(duì)象的字符串表示形式。
返回的字符串表示是 JSON 兼容的。
覆蓋:
類 Object 中的 toString
返回:
返回 PlainBooleanArray 的基于 JSON 的字符串表示。
文章標(biāo)題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSPlainBooleanArray
網(wǎng)站網(wǎng)址:http://www.5511xx.com/article/cohjoop.html


咨詢
建站咨詢
