本帖最后由 战狼 于 2014-4-25 14:24 编辑
最后一个提问是:寻找集合中小于字符串“By“的元素:
- public class TreeSetDemo2 {
- public static void main(String[] args) {
- String str = "Everthing has an end";
- String str1= "Good to begin well, better to end well";
- String str2 = "You cabbot tell a book by its cover";
- String str3= "A good book is a light to the soul";
-
- TreeSet<String> ts = new TreeSet<String>();
-
- ts.add(str);
- ts.add(str1);
- ts.add(str2);
- ts.add(str3);
- System.out.println(ts);
-
- System.out.println("第一个元素:"+ts.first());
- System.out.println("最后一个元素:"+ts.last());
- }
- }
复制代码 ” |
|