有关 Random random = new Random();
/*
* 3.对其他类型泛型的List集合进行排序,以Student为例
*/
public void testSort3() {
List<Student> studentList = new ArrayList<Student>();
Random random = new Random();//要用到随机数,就先创建一个Random类型的对象studentList.add(new Student(random.nextInt(1000)+"","Mike")); studentList.add(new Student(random.nextInt(1000)+"","Angela")); studentList.add(new Student(random.nextInt(1000)+"","Lucy"));
请教各位慕友,在Student类中定义了含参构造器中的参数id是一个String类型,想问一下random.nextInt(1000)的返回值也是一个String类型吗?
如果是的话,那前面
/*1.通过Collections.sort()方法,对Integer泛型的List集合进行排序
* 创建衣蛾Intger泛型(泛型不能用基本类型,要就得使用对应的包装类)的List集合,插入十个100以内的不重复的随机整数
* 调用Collections.sort()方法对其进行排序
*/
public void testSort1() {
List<Integer> integerList = new ArrayList<Integer>();
//插入十个100以内的不重复整数
Random random = new Random();
Integer k;
for (int i =0;i<10;i++) {
do {
k = random.nextInt(100);
}while (integerList.contains(k));
integerList.add(k);
System.out.println("成功添加整数:"+k);
}Integer类型的k怎么可以接收String类型的返回值呢?到底该怎么解释?谢谢各位慕友!