java 方法 示例
TreeSet类降序设置()方法 (TreeSet Class descendingSet() method)
descendingSet() method is available in java.util package.
java.util包中提供了destingingSet ()方法 。
descendingSet() method is used to get the elements of this TreeSet in reverse order.
DescendingSet()方法用于以相反顺序获取此TreeSet的元素。
descendingSet() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
DescendingSet()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
descendingSet() method does not throw an exception at the time of returning the navigable set.
返回可导航集时, DescendingSet()方法不会引发异常。
Syntax:
句法:
public NavigableSet descendingSet();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is NavigableSet, it gets this TreeSet elements in reverse order.
方法的返回类型为NavigableSet ,它以相反的顺序获取此TreeSet元素。
Example:
例:
// Java program to demonstrate the example
// of NavigableSet descendingSet() method of TreeSet
import java.util.*;
public class DescendingSetOfTreeSet {
public static void main(String[] args) {
// Instantiates a TreeSet object
TreeSet < String > tree_set = new TreeSet < String > ();
TreeSet < String > rev_set = new TreeSet < String > ();
// By using add() method is to add
// the given object of this TreeSet
tree_set.add("C");
tree_set.add("C++");
tree_set.add("JAVA");
tree_set.add("PHP");
tree_set.add("SFDC");
// Display TreeSet
System.out.println("TreeSet: " + tree_set);
// By using descendingSet() method is to
// return the elements of TreeSet in descending
// order to be viewed in a set
rev_set = (TreeSet) tree_set.descendingSet();
// Iterating elements
System.out.println("rev_set.descendingSet(): ");
for (Iterator itr = rev_set.iterator(); itr.hasNext();)
System.out.println(itr.next());
}
}
Output
输出量
TreeSet: [C, C++, JAVA, PHP, SFDC]
rev_set.descendingSet():
SFDC
PHP
JAVA
C++
C
翻译自: https://www.includehelp.com/java/treeset-descendingset-method-with-example.aspx
java 方法 示例