package test_set_map;
import java.util.Iterator;
import java.util.TreeSet;
public class Test_Tree {
/**
* @param args
*
* String demos[]={"hello","donghongyu","test","中国"};//排序
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String demos[] = { "chun", "hello", "test", "中国", "test" };// 与set相同不能有重复元素
TreeSet<String> str = new TreeSet<String>();
for (int i = 0; i < demos.length; i++) {
str.add(demos[i]);// 循环遍历并添加到TreeSet集合中
}
Iterator<String> itr = str.iterator();
if (str.comparator() != null) {
System.out.println("不是自然排序");
}
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
}
用TreeSet对指定字符串数组内容进行排序(1)
最新推荐文章于 2024-03-27 15:52:16 发布