[Java] Get a random value from an array

Use 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]

Recommended Posts

[Java] Get a random value from an array
Easily get an integer from a system property in Java
Get a non-empty collection from an Optional stream in java
[Ruby] Get unique elements from an array
Effective Java Item 25 Select a list from an array First half
[Java] Get multiple values from one return value
[Java] Program example to get the maximum and minimum values from an array
Output the maximum value from the array using Java standard output
Get attributes and values from an XML file in Java
Take a look at Kotlin from an Effective Java perspective
Generate Stream from an array of primitive types in Java
[Ruby] How to extract a specific value from an array under multiple conditions [select / each]
Terraform: (and Ansible: and Chef :) Extract a hash from an array where a key has a specific value.
Java learning memo (creating an array)
Get country from IP address (Java)
Run a batch file from Java
[Java] Declare and initialize an array
Access Teradata from a Java application
Get stuck in a Java primer
[Java] Conversion from array to List
How to make a Java array
Java, JS (jQuery) and Ajax. Get a specific value of JSON.
Sorting a list with an int array as an element (Java) (Comparator)
Cast an array of Strings to a List of Integers in Java
[Java] How to search for a value in an array (or list) with the contains method
[Java] array
When seeking multiple in a Java array
Java array
Java array
java (array)
Get caller information from stack trace (java)
Map without using an array in java
[Java] Array
Compare the elements of an array (Java)
Try running a Kubernetes Job from Java
[Java] Get tag information from music files
Get history from Zabbix server in Java
I want to ForEach an array with a Lambda expression in Java
java array
[Java] Array
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
If a person from Java learns PHP
[Java] How to convert one element of a String type array to an Int type
How to get an arbitrary digit from a number of 2 or more digits! !!
GetInstance () from a @Singleton class in Groovy from Java
[Java] From two Lists to one array list
Get Value from URL parameter with GetMapping ~ LocalDate ~
[Ruby] Calculation by extracting elements from an array
Connect to Aurora (MySQL) from a Java application
How to get a heapdump from a Docker container
To become a VB.net programmer from a Java shop
I get an error when adding a dependency
I tried hitting a Java method from ABCL
Programming beginners learn PHP from a Java perspective-variables-
How to get Class from Element in Java
Create Scala Seq from Java, make Scala Seq a Java List
Get unixtime (seconds) from ZonedDateTime in Scala / Java
[Java] How to get random numbers excluding specific numbers
[Android] Get random keys and values from HashMap
[LeJOS] Get EV3 sensor value remotely with Java
[Java] Get KFunction from Method / Constructor in Java [Kotlin]