Get headSet values of Java SortedSet Example

Get headSet values of Java SortedSet Example


Posted in : Java Posted on : December 6, 2010 at 6:12 PM Comments : [ 0 ]

This Java Example shows how to get the head set values from the Set.

Get headSet values of Java SortedSet Example

This Java Example shows how to get the head set values from the Set. The head set contains the elements of the set which is less than the specified set value.We use headSet(E toElement) method of SortedSet interface.  It returns a view of the portion of this set whose elements are strictly less than toElement.

Example:- HeadSetSortedSet.java

package devmanuals.com;

import java.util.*;

public class HeadSetSortedSet {
	public static void main(String args[]) {
		SortedSet Sset = new TreeSet();
		Sset.add("Gyan");
		Sset.add("Ankit");
		Sset.add("Arun");
		Sset.add("Anand");
		Sset.add("Ram");
		System.out.println("The SortedSet entries is as follows : " + Sset);
		System.out.println("The head set of the set is : "
				+ Sset.headSet("Gyan"));

	}
}

Output:-

The SortedSet entries is as follows : [Anand, Ankit, Arun, Gyan, Ram] 

The head set of the set is : [Anand, Ankit, Arun]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics