how to select a random element from an array in java
import java.util.Random;
public class RandomStringFromArray
{
public static void main(String[] args)
{
String[] arr={"1", "2", "3", "4", "5"};
Random r=new Random();
int randomNumber=r.nextInt(arr.length);
System.out.println(arr[randomNumber]);
}
}
Also in Java:
- how to get all the names of the files in a folder in java?
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- clear stringbuilder java
- java 8 string to localdate
- isnumber java
- throwing exceptions java
- java random number
- map with insertion order preserved java
- log4j with spring boot restful services
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- cosinus-1 java
- java for increment by 2
- how to add an object to a list of objects in java
- java convert edittext to double
- loop collection android
- even or odd in java
- how do I change the opacity of a JButton
- shorthand if java without else
- find the day of the week Calendar class in java
- properties java 8 maven in pom xml
- java prev permutation
- how to close a jframe in java with an if statement
- immagini java
- ARE THERE POINTER IN JAVA