java中TreeSet有什么用
TreeSet的用法
TreeSet 二叉查找書,所以結(jié)果為升序,任何順序添加打印結(jié)果都為升序?!?br>馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號: 73203。
例: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);
}
}
結(jié)果是:
[1, 2, 3, 4]
[1, 2, 4]
[1, 2, 4, 5, 7]