java.util.concurrent.ConcurrentSkipListSet的iterator()方法是Java中的內置函數,用於按升序返回此集合中元素的迭代器。句法:
ConcurrentSkipListSet.iterator()
返回值:該函數以升序返回此集合中元素的迭代器。
以下程序說明了java.util.concurrent.ConcurrentSkipListSet.iterator()的用法:
程序1:
// Java Program Demonstrate iterator()
// method of ConcurrentSkipListSet
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetIteratorExample1 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<String>
set = new ConcurrentSkipListSet<String>();
// Adding elements to this set
set.add("Gfg");
set.add("is");
set.add("fun!!");
// Returns an iterator over the elements
Iterator<String> iterator = set.iterator();
// Printing the elements of the set
while (iterator.hasNext())
System.out.print(iterator.next() + " ");
}
}
輸出:
Gfg fun!! is
程序2:
// Java Program Demonstrate iterator()
// method of ConcurrentSkipListSet */
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetIteratorExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
set.add(10);
set.add(15);
set.add(20);
set.add(25);
// Returns an iterator over the elements
Iterator<Integer> iterator = set.iterator();
// Printing the elements of the set
while (iterator.hasNext())
System.out.print(iterator.next() + " ");
}
}
輸出:
10 15 20 25
參考:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#iterator-
相關用法
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet higher()用法及代碼示例
- Java ConcurrentSkipListSet descendingSet()用法及代碼示例
- Java ConcurrentSkipListSet equals()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
- Java ConcurrentSkipListSet remove()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet iterator() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。