2.2 TreeSet的用法
TreeSet 二叉查找书,所以结果为升序,任何顺序添加打印结果都为升序。
例:2.2.1
import java.io.*;
import java.util.*;
public class TestMark_to_win {
public static void main(String args[]) {
TreeSet t = new TreeSet();
t.add("2");
t.add("1");
t.add("4");
t.add("3");
/* because the tree is binary search tree , so the result is iterator
order, so ascending order
*/
System.out.println(t);
t.remove("3");
System.out.println(t);
t.add("5");
t.add("4");
t.add("7");
System.out.println(t);
}
}
更多请见:https://blog.youkuaiyun.com/qq_44639795/article/details/102669209
本文介绍Java中TreeSet的使用方法,演示了如何添加元素、删除指定项及展示排序后的集合。通过实例代码展示了TreeSet作为二叉查找树的特性,确保集合中的元素按升序排列。
171万+

被折叠的 条评论
为什么被折叠?



