get raondom from array 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]);
}
}public static int getRandom(int[] array) {
int rnd = new Random().nextInt(array.length);
return array[rnd];
}
Also in Java:
- android get distance between two locations kotlin
- create notification android
- how to crate a list in java script
- how to remove components from a JFRame java
- bukkit java get max players
- java merge sort
- @JsonSerializer spring specific field string to date
- java observable to observer stack overflow
- how to check if a string contains only alphabets and space in java
- jsonobject to java object
- how to use lambda in java
- how to remove a certain string in a arraylist java
- java 8 list stream delete by name
- change java version command line debian
- Compilation is not supported for following modules: android. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project
- char array to arraylist java
- java string to boolean
- how to install java 8 on terminal os
- java jaxb unmarshall xml to map
- cgange background from button click java fx
- how to create a button in java
- how to print in java
- cannot lock java compile cache as it has already been locked by this process
- stack class in java