public class Demo {
public static void main(String[] args) {
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
TreeSet<Integer> ts = new TreeSet<Integer>();
Random r = new Random();
while (ts.size() < 5) {
//随机生成一个介于0到数组长度之间的角标
int i = r.nextInt(arr.length);
ts.add(arr[i]);
}
System.out.println(ts);