Wu Yuxiong - born naturally develop common java class library study notes: SortedSet Interface

import java.util.SortedSet ;
import java.util.TreeSet ;
public class TreeSetDemo05{
    public static void main(String args[]){
        The SortedSet <String> = allSet new new TreeSet <String> ();     //  
        allSet.add ( "A");     // add content 
        allSet.add ( "B");     // add content 
        allSet.add ( "C") ;     // add content 
        allSet.add ( "C");     // add content 
        allSet.add ( "C");     // add content 
        allSet.add ( "D");     // add content 
        allSet.add ( "E ");     // add content 
        System.out.println (" first element: "+ allSet.first ());
        System.out.println ( "last element:" + allSet.last ());
        System.out.println("headSet元素:" + allSet.headSet("C")) ;
        System.out.println("tailSet元素:" + allSet.tailSet("C")) ;
        System.out.println("subSet元素:" + allSet.subSet("B","D")) ;
    }
};

 

Guess you like

Origin www.cnblogs.com/tszr/p/12152711.html