java random between two strings
import java.util.Random;
public class RandomSelect {
public static void main (String [] args) {
String [] arr = {"A", "B", "C", "D"};
Random random = new Random();
// randomly selects an index from the arr
int select = random.nextInt(arr.length);
// prints out the value at the randomly selected index
System.out.println("Random String selected: " + arr[select]);
}
}String[] s = {"your", "array", "of", "strings"};
Random ran = new Random();
String s_ran = s[ran.nextInt(s.length)];
Also in Java:
- addition of two numbers in java
- java round double to 2 decimal places
- take a value from keyboard java
- how to skip a line in java
- spigot actionbar
- java exit
- how to change the color of a menubar in java
- eliminar fila jtable java
- android studio clear views of layout
- bracket balancing program in java
- java doreturn void
- read csv java
- java string regexp replace
- how to get a user input in java
- write file java
- java find duplicates in array
- import
- vector in java
- .length array java
- spark write partitionby
- java stack
- java find biggest number in array
- classes in java
- difference between java and javax