我有一个String
数组:
String [] array={"1","2","3","4","5","6","7","8","9"};
我将其转换为数组列表:
ArrayList<String> al = new ArrayList<String>(Arrays.asList(array));
我想从我的ArrayList中获取一个随机值。
答案 0 :(得分:5)
使用Random
类来执行此操作,方法nextInt
的参数是要返回的随机数的界限。它必须是积极的:
Random random = new Random();
yourList.get(random.nextInt(yourList.size()));
答案 1 :(得分:0)