Use the Random.nextInt(int) method:

final String[] proper_noun = {"Fred", "Jane", "Richard Nixon", "Miss America"};
Random random = new Random();
int index = random.nextInt(proper_noun.length);
System.out.println(proper_noun[index]);

This code is not completely safe: one time out of four it'll choose Richard Nixon.

To quote a documentation Random.nextInt(int):

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)

In your case passing an array length to the nextInt will do the trick - you'll get the random array index in the range [0; your_array.length)

Answer from Nigel Tufnel on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ How-do-I-pick-up-a-random-string-from-an-array-of-strings-in-Java
How to pick up a random string from an array of strings in Java - Quora
Answer (1 of 4): It is quite easy. You only need to generate a random number that acts as the index value for String array. You can generate random value using Random class defined in java.util package.
๐ŸŒ
Dirask
dirask.com โ€บ posts โ€บ Java-pick-random-string-from-array-of-strings-y1xln1
Java - pick random string from array of strings
January 13, 2023 - As nextInt function is called we pass int bound to have results within array size. import java.util.concurrent.ThreadLocalRandom; public class JavaRandomStringFromArray { public static String randomStringFromArr() { String[] arr = {"A", "B", ...
๐ŸŒ
SitePoint
sitepoint.com โ€บ get started
Random String from Array - Get Started - SitePoint Forums | Web Development & Design Community
August 30, 2014 - How can I now return a random string from the following array? import java.util.Random; public class RpsBW { public void setObjects() { String objects[] = {"Rock", "Paper", "Scissors"}; } public sโ€ฆ
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ generate-a-random-string-in-java
Generate a random string in Java
import java.util.Random; public class Demo { public static void main(String[] args) { String[] strArr = { "P", "Q", "R", "S","T", "U", "V", "W" }; Random rand = new Random(); int res = rand.nextInt(strArr.length); System.out.println("Displaying a random string = " + strArr[res]); } }
๐ŸŒ
ExamTray
examtray.com โ€บ java โ€บ java-program-how-print-random-element-or-index-array-arraylist
Java Program: How to Print or Get or Find a Random Element of An Array, ArrayList | ExamTray
July 23, 2025 - import java.util.Random; public class MyClass { public static void main(String[] args) { int ary[] = {10,11,12,13,14,15}; Random ran = new Random(); int randomNumber = ran.nextInt(ary.length); int randomArrayElement = ary[randomNumber]; } } Last Minute Java Tutorial is already available on ...
๐ŸŒ
Narkive
programming.comp.narkive.com โ€บ YK1cYpiT โ€บ picking-a-random-string-from-an-array-in-java
Picking a random string from an array in Java?
For what it's worth: String myStrings[] = // whatever String randomStr = myStrings[ (int) (Math.random() * myStrings.length) ]; That's the proper way. Math.random() always returns a value strictly less than 1, so when multiplied by myStrings.length and truncated to an int, it will be a random ...
Find elsewhere
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 562577 โ€บ java โ€บ SOLVED-randomly-String-array-random
[SOLVED]How to randomly get a String from an array in a random amount of times. [Solved] (Beginning Java forum at Coderanch)
September 25, 2019 - My desired output would be: random String, random String, random String, random String another ex: Plates, Silver Coins, Dressing Table, Candy Wrapper, Chipped Bat Please note that I want all of the randomly picked strings stored in ONE variable. EDIT: solved it. My idiotic brain did not realize to just add the below code in the for loop. ... Sorry for the double post, and the useless thread, but I solved it . ... Boost this thread! ... Randomly shuffling an array.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 397689 โ€บ java โ€บ creating-random-strings-array
help with creating random strings in an array (Beginning Java forum at Coderanch)
November 10, 2004 - Maybe: just to get a feel for the ints you're going to get. If you want to use one of those ints to pick a random letter out of the alphabet you'll probably use the int as an index into your array of letters. That's a fine idea, but look at those ints. Some are going to be too big for your array. Read up on Random javadoc to see how to get numbers in the range you want ...
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ generate array of random strings in java
Generate array of random strings in Java - CodeSpeedy
April 25, 2023 - We use java.util.Random class for generating the random string and store in java array string object that contains the elements of string data type.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ java โ€“ generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - Learn how to generate random numbers in Java - both unbounded as well as within a given interval. ... Learn how the JVM optimizes the amount of memory allocated to String storage in the Java String Pool. ... @Test public void givenUsingPlainJava_whenGeneratingRandomStringUnbounded_thenCorrect() { byte[] array = new byte[7]; // length is bounded by 7 new Random().nextBytes(array); String generatedString = new String(array, Charset.forName("UTF-8")); System.out.println(generatedString); }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ generate-random-string-of-given-size-in-java
Generate random String of given size in Java - GeeksforGeeks
July 11, 2025 - // Java program generate a random AlphaNumeric String // using CharSet method import java.util.*; import java.nio.charset.*; class RandomString { static String getAlphaNumericString(int n) { // length is bounded by 256 Character byte[] array ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 64973471 โ€บ how-to-get-a-random-string-from-a-string-array
java - How to get a random String from a String array - Stack Overflow
November 24, 2020 - it will generate a random number in range of Movies array length and then return a random movie in that range: public String randomSnack() { int rnd = new Random().nextInt(Movies.length); return Movies[rnd]; } ... Sign up to request clarification ...