LoginSignup
0
2

More than 3 years have passed since last update.

[Android]HashMapからランダムなキーと値を取得する

Posted at

メモエントリー。

List<String> keysAsArray = new ArrayList<>(map.keySet());
Random random = new Random();
String key = keysAsArray.get(random.nextInt(keysAsArray.size()));
String value = map.get(key);
0
2
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
0
2