Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

get random element from string array java

String random = (fruits[new Random().nextInt(fruits.length)]);
Comment

get random word from list java

import java.util.Random;

public class Selection
{    
  	public static void main(String[] args)    
    {       
        Random rand = new Random(); 
      	String[] animals = {"Dog", "Cat", "Fish", "Turtle", "Penguin"}; // array of animals
      	System.out.println("Console picked " + animals[rand.nextInt(animals.length)]); // prints the random animal selected from array
    }
}
Comment

get random element from string array java

String[] fruits = {"Apple","Mango","Peach","Banana","Orange","Grapes","Watermelon","Tomato"};
Comment

PREVIOUS NEXT
Code Example
Java :: java or symbol 
Java :: get certain character from string java 
Java :: java program to print 1 to 100 using for loop 
Java :: check if all values are same in list java 
Java :: java string split from input string 
Java :: sum of 1D array(JAVA) 
Java :: play sound in java 
Java :: @notblank not working in spring boot 
Java :: how to add to a file in java 
Java :: java reverse linked list 
Java :: selenide wait 
Java :: Error: Could not find or load main class -Djava.library.path=.home.hdoop.hadoop-3.3.0.lib.native 
Java :: how to resize image in android programmatically 
Java :: what is java plug-in 
Java :: make window visible java 
Java :: remove spaces at beginning and end of string java 
Java :: change button text onclick javca 
Java :: how to compare current date and time with another date and time in android 
Java :: calling method in java 
Java :: find minimum number in array java 
Java :: close a popup selenium python 
Java :: how to detect device javascirpt 
Java :: comparable on a generic class java 
Java :: how to use random bound on doubles java 
Java :: java convert to roman numerals 
Java :: string to string array java 
Java :: how to iterate pixels image java 
Java :: split string regex java 
Java :: java spring boot json deserialize date inaccurate 
Java :: create new empty list java 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =