java.util.concurrent.ConcurrentSkipListMap的size()方法是Java中的內置函數,它返回映射到此映射的鍵數。 size()方法不是恒定時間操作。如果映射包含多個Integer.MAX_VALUE元素,則返回映射的最大值。
用法:
public int size()
參數:該函數不接受任何參數。
返回值:該函數返回此映射中的元素數。
以下示例程序旨在說明上述方法:
示例1:
// Java Program Demonstrate size()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap<Integer, Integer>
mpp = new ConcurrentSkipListMap<Integer,
Integer>();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// print size of map
System.out.println(mpp.size());
}
}
輸出:
5
示例2:
// Java Program Demonstrate size()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap<Integer, Integer>
mpp = new ConcurrentSkipListMap<Integer,
Integer>();
// Adding elements to this map
for (int i = 1; i <= 15; i++)
mpp.put(i, i);
// print size of map
System.out.println(mpp.size());
}
}
輸出:
15
參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#size–
相關用法
- Java ConcurrentSkipListMap put()用法及代碼示例
- Java ConcurrentSkipListMap isEmpty()用法及代碼示例
- Java ConcurrentSkipListMap containsKey()用法及代碼示例
- Java ConcurrentSkipListMap remove()用法及代碼示例
- Java ConcurrentSkipListMap clone()用法及代碼示例
- Java ConcurrentSkipListMap ceilingKey()用法及代碼示例
- Java ConcurrentSkipListMap equals()用法及代碼示例
- Java ConcurrentSkipListMap containsValue()用法及代碼示例
- Java ConcurrentSkipListMap clear()用法及代碼示例
- Java Files size()用法及代碼示例
- Java Dictionary size()用法及代碼示例
- Java ArrayList size()用法及代碼示例
- Java SortedSet size()用法及代碼示例
- Java List size()用法及代碼示例
- Java AbstractMap size()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 ConcurrentSkipListMap size() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。