public void whenIteratingTreeSet_shouldIterateTreeSetInDescendingOrder() { TreeSet<String> treeSet = new TreeSet<>(); treeSet.add("First"); treeSet.add("Second"); treeSet.add("Third"); Iterator<String> itr = treeSet.descendingIterator(); while (itr.hasNext()) { System.out.println(itr...
另外,TreeSet可以降序排序输出,下面例子: @TestpublicvoidwhenIteratingTreeSet_shouldIterateTreeSetInDescendingOrder(){TreeSet<String>treeSet=newTreeSet();treeSet.add("First");treeSet.add("Second");treeSet.add("Third");Iterator<String>itr=treeSet.descendingIterator();while(itr.hasNext()){System.ou...
Iterator iterator2;40iterator2 =treeReverse.iterator();41//displaying the Tree set data42System.out.println("Tree set data in reverse order for Integer type: ");43while(iterator2.hasNext()) {44System.out.println(iterator2.next() + " ");45}46}47} 打印输出: Tree set data in reverse o...
@Test public void whenIteratingTreeSet_shouldIterateTreeSetInDescendingOrder() { TreeSet<String> treeSet = new TreeSet<>(); treeSet.add("First"); treeSet.add("Second"); treeSet.add("Third"); Iterator<String> itr = treeSet.descendingIterator(); while (itr.hasNext()) { System.out.prin...
Returns an iterator over the elements in this set in descending order. [Android.Runtime.Register("descendingIterator", "()Ljava/util/Iterator;", "GetDescendingIteratorHandler")] public virtual Java.Util.IIterator? DescendingIterator (); Returns ...
// Java program to iterate TreeSet collection// in descending orderimportjava.io.*;importjava.util.*;publicclassMain{publicstaticvoidmain(String args[]){TreeSet<Integer>tree=newTreeSet<Integer>();tree.add(25);tree.add(20);tree.add(35);tree.add(30);Iterator<Integer>iterator=tree.descendingI...
* @return an iterator over the elements in this set in ascending order */ public Iterator<E> iterator() { return m.navigableKeySet().iterator(); } /** * Returns an iterator over the elements in this set in descending order. *
Returns an iterator over the elements in this set in descending order. Specified by: descendingIteratorin interfaceNavigableSet<E> Returns: an iterator over the elements in this set in descending order Since: 1.6 isEmpty public boolean isEmpty() ...
Iterator<E> an iterator over the elements in this set in descending orderdescendingSet Added in API level 9 NavigableSet<E> descendingSet () 返回此集合中包含的元素的逆序视图。 降序集由该集支持,因此对集的更改反映在降序集中,反之亦然。 如果两个集合中的任何一个在迭代过程中被修改(除了通过迭代器...
int size(): returns the number of elements in the TreeSet. Iterator<E> iterator(): returns an iterator over the elements in this set inascending order. Iterator<E> descendingIterator(): returns an iterator over the elements in this set in descending order. ...