为什么我会重复?
package com.project;
import java.util.List;
import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;
public class Imath {
Integer k;
public void testSort(){
List<String> stringlist=new ArrayList<String>();
Random random=new Random();
for(int i=0;i<10;i++){
do{
k=random.nextInt(10);
}while(stringlist.contains(k));
String b=String.valueOf(k);
stringlist.add(b);
}
System.out.println("~~~~~~~~~~排序前~~~~~~~");
for(String str:stringlist){
System.out.println("元素:"+str);
}
Collections.sort(stringlist);
System.out.println("~~~~~~~~~~排序后~~~~~~~");
for(String str:stringlist){
System.out.println("元素:"+str);
}
}
public static void main(String[] args) {
Imath math=new Imath();
math.testSort();
}
}