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
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. ... Keep teams on track.
🌐
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]); } }
🌐
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); }
🌐
Dirask
dirask.com › posts › Java-pick-random-string-from-array-of-strings-y1xln1
Java - pick random string from array of strings
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", ...
🌐
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
🌐
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
September 25, 2019 - 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 ...
🌐
CodeSpeedy
codespeedy.com › home › generate array of random strings in java
Generate array of random strings in Java - CodeSpeedy
January 18, 2022 - 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.
🌐
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…
🌐
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 - I'll give you a piece of code: letter = alphabet[r.nextInt(alphabet.length)] nextInt(x) returns an integer >= 0 and <x This gives you one random letter. You can assemble a String from letters using StringBuffer, you can easily make StringBuffers into Strings with a String constructor, and you can put references to your Strings in a String[] array.
🌐
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)
October 2, 2025 - 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.
🌐
javathinking
javathinking.com › blog › random-string-from-string-array-list
How to Pick a Random String from a String Array in Java: Example with Country List — javathinking.com
March 18, 2021 - The java.util.Random class is the most straightforward way to generate random numbers in Java. To pick a random string from an array, follow these steps:
🌐
YouTube
youtube.com › asim code
How to randomly pick an element from an array in Java - YouTube
In this video we will learn how to randomly pick an element from an array in Java. Please subscribe to support Asim Code!https://www.youtube.com/channel/UC2w...
Published   January 26, 2021
Views   8K