Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 字符串数组列表中的随机字符串
我怎样才能让它在我可以按下一个按钮的地方,它从我已经设置的一长串其他字符串中随机显示一个刺(单词)。
List<String> list = new ArrayList<String>(); list.add(...); list.add(...); list.add(...); Random rand = new Random(); String random = list.get(rand.nextInt(list.size()));
或者:
Collections.shuffle(list); String random = list.get(0);