Example:
import java.util.*;
class demo
{
public static void main(String[] args){
TreeSet
ts.add(35);
ts.add(54);
ts.add(23);
ts.add(7);
ts.add(33);
ts.add(15);
ts.add(3);
ts.add(30);
TreeSet
head=(TreeSet)ts.headSet(30);
System.out.println("elements less than 30:"+head);
TreeSet
tail=(TreeSet)ts.tailSet(30);
System.out.println("elements greater than 30:"+tail);
}};
Output
elements less than 30:[3, 7, 15, 23]
elements greater than 30:[30, 33, 35, 54]
No comments:
Post a Comment