TreeSet last Example

TreeSet class last example. This example shows you how to use last method.


TreeSet class last example.public Object last() Returns the last (highest) element currently in this set.

Here is the code

/**
 * @ # Last.java
 * A class repersenting use to last method 
 * of TreeSet class in java.util package
 * version 23 May 2008
 * author Rose India 
 */
import java.util.*;

public class Last {

    public static void main(String args[]) {
        TreeSet ts = new TreeSet();
        // Add the elements to the set and display it:
        System.out.println("Element is added :" + ts.add(10));
        System.out.println("Element is added :" + ts.add(20));
        System.out.println("Element is added :" + ts.add(15));
        
        System.out.println("All element of the TreeSet "+ts);
        
        System.out.println("Last elemrnt of the TreeSet "+ts.last());
    }
}

Output
Element is added :true
Element is added :true
Element is added :true
All element of the TreeSet [10, 15, 20]
Last elemrnt of the TreeSet 20

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US