通过util.Random获取随机值的方法
List<Integer> nums 不能用 nums[rand.nextInt(nums.length)] 这种下标方式访问,因为 List 没有 length 属性,也不能用 [] 取值。
解决方法:
- 用 nums.size() 获取长度
- 用 nums.get(index) 获取元素
修改如下:
int pivot = nums.get(rand.nextInt(nums.size()));
List<Integer> nums 不能用 nums[rand.nextInt(nums.length)] 这种下标方式访问,因为 List 没有 length 属性,也不能用 [] 取值。
解决方法:
int pivot = nums.get(rand.nextInt(nums.size()));