[JAVA] [Android] Get random keys and values from HashMap

Memo entry.

List<String> keysAsArray = new ArrayList<>(map.keySet());
Random random = new Random();
String key = keysAsArray.get(random.nextInt(keysAsArray.size()));
String value = map.get(key);

Recommended Posts

[Android] Get random keys and values from HashMap
Get attributes and values from an XML file in Java
Get TypeElement and TypeMirror from Class
Write keys and values in Ruby
About go get and go install from Go1.16
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
About the speed when fetching values from HashMap
[Java] Get multiple values from one return value
[Java] Get a random value from an array
Reverse Enum constants from strings and values in Java