E
last()
Returns
the highest element currently in this set.
import java.util.*; class TreeSetLast{ public static void main(String args[]){ TreeSet<Integer> mySet = new TreeSet<> (); /* Add Elements to mySet */ for(int i=20; i>0; i-=2) mySet.add(i); System.out.println("Elements in mySet are"); System.out.println(mySet); System.out.println("\nHighest Element in the Set is"); System.out.println(mySet.last()); } }
Output
Elements in mySet are [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] Highest Element in the Set is 20
No comments:
Post a Comment