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.
重複の可能性: 文字列配列リストからのランダムな文字列
ボタンを押すと、すでに設定した他の文字列の長いリストからランダムに1つの文字列(単語)が表示されるようにするにはどうすればよいですか。
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);