Saturday 26 April 2014

TreeSet : first : Get the lowest Element currently in the Set

E first()
Returns the lowest element currently in this set.

import java.util.*;

class TreeSetFirst{
 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("\nLowest Element in the Set is");
  System.out.println(mySet.first());
 }
}

Output
Elements in mySet are
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

Lowest Element in the Set is
2




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment