package mianshiti;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class T2 {
/**
* 将List集合下包含数字的元素去掉
*/
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<>();
Random r = new Random();
while(al.size() < 10) {
int x = r.nextInt(20) + 1;
if(!al.contains(x)) {
al.add(x);
}
}
Collections.sort(al);
for (Integer integer : al) {
System.out.print(integer + " " );
}
/*for (Integer integer : al) {
System.out.print(integer + " ");
}*/
//Integer[] arr = al.toArray(new int[10]);
}
}
|
|