import java.util.*;
import java.io.*;
public class Test_5
{
public static void main(String [] args)
{
//获取键盘录入
BufferedReader bufr =
new BufferedReader(new InputStreamReader(System.in));
//定义一个集合容易存放字符串.
TreeSet<String> ts = new TreeSet<String>(Collections.reverseOrder());
String line = null;
try
{
while((line =bufr.readLine())!=null)
{
if(line.equals("end"))
break;
ts.add(line);
}
/*
Iterator it = ts.iterator();
while(it.hasNext())
{
String str = (String)it.next();
System.out.println(str);
}
*/
System.out.println(ts);
}
catch(IOException e)
{
throw new RuntimeException("写入失败");
}
finally
{
if(bufr!=null)
try
{
bufr.close();
}
catch(IOException e)
{
throw new RuntimeException("关闭失败");
}
}
}
}
调用了Collections.reverseOrder()方法最后为什么结果没有倒序打印出来??求大神告知. |
|