java random between two strings

Solutions on MaxInterview for java random between two strings by the best coders in the world

showing results for - "java random between two strings"
Matías
26 Nov 2016
1import java.util.Random;
2public class RandomSelect {
3
4    public static void main (String [] args) {
5
6         String [] arr = {"A", "B", "C", "D"};
7         Random random = new Random();
8
9         // randomly selects an index from the arr
10         int select = random.nextInt(arr.length); 
11
12         // prints out the value at the randomly selected index
13         System.out.println("Random String selected: " + arr[select]); 
14    }
15}
Julian
12 Jan 2021
1String[] s = {"your", "array", "of", "strings"};
2
3Random ran = new Random();
4String s_ran = s[ran.nextInt(s.length)];