Get subSet values of Java SortedSet Example

Get subSet values of Java SortedSet Example


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

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

Get subSet values of Java SortedSet Example

This Java Example shows how to get the sub set values from the Set. The sub set contains the elements of the set which is between the specified set values range.We use subSet(E fromElement, E toElement) method of SortedSet interface.  It returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.

Example:- SubSetSortedSet.java

package devmanuals.com;

import java.util.*;

public class SubSetSortedSet {
	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 sub set of the set is : "
				+ Sset.subSet("Ankit", "Ram"));

	}
}

Output:-

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

The sub set of the set is : [Ankit, Arun, Gyan]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics