Listing 6: head_sub_tailSetDemo.java
import java.util.*;
    
    public class head_sub_tailSetDemo{
    
        public static void seeElements(SortedSet SS,String info)
            {
            //see the elements
            System.out.println(info);              
            Iterator i=SS.iterator();
            while(i.hasNext()){
                System.out.println(i.next());
            }           
           }       
        
        public static void main(String args[]) {
    
            //create a SortedSet -> tree structure    
            SortedSet SS=new TreeSet();                                       
            
            //create a NavigableSet
            NavigableSet NS=(NavigableSet)(SS);

            //populate the NS            
            NS.add("Hydro");
            NS.add("George");
            NS.add("Any");
            NS.add("Martin");
            NS.add("Wallace");
 
            //headSet - exclusive          
            System.out.println("----------------------------------------");                    
            SortedSet SSheadSetE=NS.headSet("Martin");            
            seeElements(SSheadSetE,"headSet exclusive:");            
            System.out.println("----------------------------------------"); 
            
             //headSet - inclusive
            System.out.println("----------------------------------------");                    
            SortedSet SSheadSetI=NS.headSet("Martin",true);            
            seeElements(SSheadSetI,"headSet inclusive:");            
            System.out.println("----------------------------------------"); 

            //subSet - (inclusive,exclusive)            
            System.out.println("----------------------------------------");                    
            SortedSet SSsubSetIE=NS.subSet("Any","Wallace");            
            seeElements(SSsubSetIE,"subSet (inclusive,exclusive):");            
            System.out.println("----------------------------------------"); 

            //subSet - (inclusive,inclusive)            
            System.out.println("----------------------------------------");                    
            SortedSet SSsubSetII=NS.subSet("Any",true,"Wallace",true);            
            seeElements(SSsubSetII,"subSet (inclusive,inclusive):");            
            System.out.println("----------------------------------------"); 

            //subSet - (exclusive,exclusive)            
            System.out.println("----------------------------------------");                    
            SortedSet SSsubSetEE=NS.subSet("Any",false,"Wallace",false);            
            seeElements(SSsubSetEE,"subSet (exclusive,exclusive):");            
            System.out.println("----------------------------------------"); 

            //subSet - (exclusive,inclusive)            
            System.out.println("----------------------------------------");                    
            SortedSet SSsubSetEI=NS.subSet("Any",false,"Wallace",true);            
            seeElements(SSsubSetEI,"subSet (exclusive,inclusive):");            
            System.out.println("----------------------------------------"); 

            //tailSet - inclusive
            System.out.println("----------------------------------------");                    
            SortedSet SStailSetI=NS.tailSet("Martin");            
            seeElements(SStailSetI,"tailSet inclusive:");            
            System.out.println("----------------------------------------");                            
            
            //tailSet - exclusvie
            System.out.println("----------------------------------------");                    
            SortedSet SStailSetE=NS.tailSet("Martin",false);            
            seeElements(SStailSetE,"tailSet exclusvie:");            
            System.out.println("----------------------------------------");                            
            }
    }

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.