treeset java_Java TreeSet Higher()方法与示例
treeset java
TreeSet類Higher()方法 (TreeSet Class higher() method)
higher() method is available in java.util package.
Higher()方法在java.util包中可用。
higher() method is used to return the lowest element in this TreeSet that is higher than the specified element (ele).
Higher()方法用于返回此TreeSet中比指定元素(ele)高的最低元素。
higher() 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.
Higher()方法是一種非靜態(tài)方法,只能通過類對(duì)象訪問,如果嘗試使用類名稱訪問該方法,則會(huì)收到錯(cuò)誤消息。
higher() method may throw an exception at the time of returning the element.
Higher()方法在返回元素時(shí)可能會(huì)引發(fā)異常。
- ClassCastException: This exception may throw when the given parameter is incompatible to compare.ClassCastException :如果給定參數(shù)不兼容以進(jìn)行比較,則可能引發(fā)此異常。
- NullPointerException: This exception may throw when the given element is null exists.NullPointerException :當(dāng)給定元素為null時(shí),可能引發(fā)此異常。
Syntax:
句法:
public Element higher(Element ele);Parameter(s):
參數(shù):
Element ele – represents the element (ele) is to be checked with other element exists in this TreeSet.
元素ele –表示要與該TreeSet中存在的其他元素檢查元素(ele)。
Return value:
返回值:
The return type of the method is Element, it returns least element higher than the given element (ele) in this TreeSet otherwise it returns null.
方法的返回類型為Element ,它返回比此TreeSet中給定元素(ele)高的最小元素,否則返回null。
Example:
例:
// Java program to demonstrate the example // of Element higher(Element ele) method of TreeSet import java.util.*;public class HigherOfTreeSet {public static void main(String[] args) {// Instantiates a TreeSet objectTreeSet < String > tree_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 TreeSetSystem.out.println("TreeSet: " + tree_set);// By using higher() method is to// return the least element higher than// the given element i.e. PHPObject least = tree_set.higher("Microservices");// Display leastSystem.out.println("tree_set.higher(Microservices): " + least);} }Output
輸出量
TreeSet: [C, C++, JAVA, PHP, SFDC] tree_set.higher(Microservices): PHP翻譯自: https://www.includehelp.com/java/treeset-higher-method-with-example.aspx
treeset java
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的treeset java_Java TreeSet Higher()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: setdefault_Java语言环境s
- 下一篇: java indexof_Java V