目录

E last()

描述 (Description)

last()方法用于返回此set中当前的最后一个(最高)元素。

声明 (Declaration)

以下是java.util.TreeSet.last()方法的声明。

public E last()

参数 (Parameters)

NA

返回值 (Return Value)

方法调用返回此集合中当前的最后一个(最高)元素。

异常 (Exception)

NoSuchElementException - 如果此set为空,则抛出此异常。

例子 (Example)

以下示例显示了java.util.TreeSet.last()方法的用法。

package com.iowiki;
import java.util.TreeSet;
public class TreeSetDemo {
   public static void main(String[] args) {
      // creating a TreeSet 
      TreeSet <Integer>treeadd = new TreeSet<Integer>();
      // adding in the tree set
      treeadd.add(1);
      treeadd.add(13);
      treeadd.add(17);
      treeadd.add(2);
      // displaying the last highest element
      System.out.println("Last highest element: "+treeadd.last());    
   }    
}

让我们编译并运行上面的程序,这将产生以下结果。

Last highest element: 17 
↑回到顶部↑
WIKI教程 @2018