Package util; import Java. util. iterator; import Java. util. sortedset; import Java. util. treeset;/***** @ author yjmao * @ deprecated sortedset common method summary * @ version v1.0.0 * @ see these elements are sorted in their natural order, or sort by the comparator that is usually provided when an ordered set is created. */Public class learnsortedset {public static void main (string [] ARGs) {// easymethod (); // hardmethod (); // It is wrong to define it directly, because hashset is unordered, and sortedset is ordered // sortedset <string> Seth = new hashset <string> (); sortedset <string> set = new treeset <string> (); set. add ("AAA"); set. add ("BBB"); set. add ("CCC"); set. add ("DDD"); set. add ("eee"); iterator <string> iterator = set. iterator (); While (iterator. hasnext () {string S = iterator. Next (); system. Err. Print (S + ",") ;}// first (): returns the current first (lowest) element in this set. String Fe = set. first (); system. err. println ("\ n first element:" + Fe); // last (): returns the last (highest) element in the set. String Le = set. last (); system. err. println ("last element:" + le); // headset (): returns some views of this set. Its elements are strictly less than toelement. System. err. print ("the element smaller than CCC (not included) in the Set:"); sortedset <string> heade = set. headset ("CCC"); iterator <string> iteratorh = heade. iterator (); While (iteratorh. hasnext () {string S = iteratorh. next (); system. err. print (S + ",") ;}// tailset (): returns some views of this set. The element is greater than or equal to fromelement. System. err. print ("\ n set contains more elements than CCC (including):"); sortedset <string> taile = set. tailset ("CCC"); iterator <string> iteratore = taile. iterator (); While (iteratore. hasnext () {string S = iteratore. next (); system. err. print (S + ",") ;}// subset (): returns some views of this set, whose elements are from fromelement (included) to toelement (not included ). System. err. elements in the print ("\ n set between CCC (inclusive) and EEE (excluded):"); sortedset <string> sube = set. subset ("CCC", "eee"); iterator <string> iteratort = sube. iterator (); While (iteratort. hasnext () {string S = iteratort. next (); system. err. print (S + ",");}}}