LoginSignup
1
1

More than 3 years have passed since last update.

[Java] 配列からランダムに値を取得する

Last updated at Posted at 2020-10-26

Collections.shuffleを使用


import java.util.Arrays;
import java.util.Collections;
import java.util.List;


List<String> list = Arrays.asList("AA", "BB", "CC");
System.out.println(list); // =>  [AA, BB, CC]

Collections.shuffle(list);
System.out.println(list);  // => [CC, AA, BB]
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1